diff --git a/src/lib/app/profileupdater.cpp b/src/lib/app/profileupdater.cpp index 75d877224..67503f177 100644 --- a/src/lib/app/profileupdater.cpp +++ b/src/lib/app/profileupdater.cpp @@ -183,6 +183,5 @@ void ProfileUpdater::update140() mApp->connectDatabase(); QSqlQuery query; - query.exec("ALTER TABLE search_engines ADD COLUMN method TEXT"); - query.exec("UPDATE search_engines SET method='GET'"); + query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT"); } diff --git a/src/lib/data/data/browsedata.db b/src/lib/data/data/browsedata.db index e382cbb44..7013963c9 100644 Binary files a/src/lib/data/data/browsedata.db and b/src/lib/data/data/browsedata.db differ diff --git a/src/lib/navigation/websearchbar.cpp b/src/lib/navigation/websearchbar.cpp index 83fe755dd..bdf998a66 100644 --- a/src/lib/navigation/websearchbar.cpp +++ b/src/lib/navigation/websearchbar.cpp @@ -205,13 +205,19 @@ void WebSearchBar::instantSearchChanged(bool enable) void WebSearchBar::search() { p_QupZilla->weView()->setFocus(); - p_QupZilla->weView()->load(m_searchManager->searchUrl(m_activeEngine, text())); + + SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text()); + p_QupZilla->weView()->load(res.request, res.operation, res.data); } void WebSearchBar::searchInNewTab() { p_QupZilla->weView()->setFocus(); - p_QupZilla->tabWidget()->addView(m_searchManager->searchUrl(m_activeEngine, text())); + + int index = p_QupZilla->tabWidget()->addView(QUrl()); + + SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text()); + p_QupZilla->weView(index)->load(res.request, res.operation, res.data); } void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu) diff --git a/src/lib/opensearch/searchenginesmanager.cpp b/src/lib/opensearch/searchenginesmanager.cpp index 3a58dc8b9..a1a5d36ef 100644 --- a/src/lib/opensearch/searchenginesmanager.cpp +++ b/src/lib/opensearch/searchenginesmanager.cpp @@ -67,15 +67,16 @@ void SearchEnginesManager::loadSettings() m_settingsLoaded = true; QSqlQuery query; - query.exec("SELECT name, icon, url, shortcut, method, suggestionsUrl FROM search_engines"); + query.exec("SELECT name, icon, url, shortcut, suggestionsUrl, suggestionsParameters, postData FROM search_engines"); while (query.next()) { Engine en; en.name = query.value(0).toString(); en.icon = qIconProvider->iconFromBase64(query.value(1).toByteArray()); en.url = query.value(2).toString(); en.shortcut = query.value(3).toString(); - en.method = query.value(4).toString(); - en.suggestionsUrl = query.value(5).toString(); + en.suggestionsUrl = query.value(4).toString(); + en.suggestionsParameters = query.value(5).toByteArray(); + en.postData = query.value(6).toByteArray(); m_allEngines.append(en); @@ -110,19 +111,26 @@ SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut) return returnEngine; } -QUrl SearchEnginesManager::searchUrl(const Engine &engine, const QString &string) +SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const Engine &engine, const QString &string) { ENSURE_LOADED; QByteArray url = engine.url.toUtf8(); url.replace(QLatin1String("%s"), QUrl::toPercentEncoding(string)); - return QUrl::fromEncoded(url); + + SearchResult result; + result.request = QNetworkRequest(QUrl::fromEncoded(url)); + result.operation = QNetworkAccessManager::GetOperation; + + return result; } -QUrl SearchEnginesManager::searchUrl(const QString &string) +SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const QString &string) { + ENSURE_LOADED; + const Engine en = qzSettings->searchWithDefaultEngine ? m_defaultEngine : m_activeEngine; - return searchUrl(en, string); + return searchResult(en, string); } void SearchEnginesManager::restoreDefaults() @@ -447,14 +455,14 @@ void SearchEnginesManager::saveSettings() query.exec("DELETE FROM search_engines"); foreach (const Engine &en, m_allEngines) { - query.prepare("INSERT INTO search_engines (name, icon, url, shortcut, method, suggestionsUrl, suggestionsParameters) VALUES (?, ?, ?, ?, ?, ?)"); + query.prepare("INSERT INTO search_engines (name, icon, url, shortcut, suggestionsUrl, suggestionsParameters, postData) VALUES (?, ?, ?, ?, ?, ?)"); query.addBindValue(en.name); query.addBindValue(qIconProvider->iconToBase64(en.icon)); query.addBindValue(en.url); query.addBindValue(en.shortcut); - query.addBindValue(en.method); query.addBindValue(en.suggestionsUrl); query.addBindValue(en.suggestionsParameters); + query.addBindValue(en.postData); query.exec(); } diff --git a/src/lib/opensearch/searchenginesmanager.h b/src/lib/opensearch/searchenginesmanager.h index 59c81a707..ce709bbaf 100644 --- a/src/lib/opensearch/searchenginesmanager.h +++ b/src/lib/opensearch/searchenginesmanager.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "qz_namespace.h" #include "opensearchengine.h" @@ -41,10 +42,10 @@ public: QIcon icon; QString url; QString shortcut; - QString method; QString suggestionsUrl; QByteArray suggestionsParameters; + QByteArray postData; bool operator==(const Engine &other) const { return (this->name == other.name && @@ -53,8 +54,14 @@ public: } }; - QUrl searchUrl(const Engine &engine, const QString &string); - QUrl searchUrl(const QString &string); + struct SearchResult { + QNetworkRequest request; + QNetworkAccessManager::Operation operation; + QByteArray data; + }; + + SearchResult searchResult(const Engine &engine, const QString &string); + SearchResult searchResult(const QString &string); void addEngine(const QUrl &url); void addEngine(OpenSearchEngine* engine); diff --git a/src/lib/popupwindow/popupwebview.cpp b/src/lib/popupwindow/popupwebview.cpp index af7d97389..95cb7da42 100644 --- a/src/lib/popupwindow/popupwebview.cpp +++ b/src/lib/popupwindow/popupwebview.cpp @@ -20,6 +20,7 @@ #include "mainapplication.h" #include "qupzilla.h" #include "tabwidget.h" +#include "tabbedwebview.h" #include "iconprovider.h" #include "enhancedmenu.h" @@ -59,18 +60,19 @@ QWidget* PopupWebView::overlayForJsAlert() return this; } -void PopupWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position) +void PopupWebView::loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, const QByteArray &data, Qz::NewTabPositionFlag position) { Q_UNUSED(position) QupZilla* window = mApp->getWindow(); if (window) { - QNetworkRequest req(urla); - req.setRawHeader("Referer", url().toEncoded()); - req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); + QNetworkRequest r(req); + r.setRawHeader("Referer", url().toEncoded()); + r.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); - window->tabWidget()->addView(req, Qz::NT_SelectedTab); + int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab); + window->weView(index)->load(r, op, data); window->raise(); } } diff --git a/src/lib/popupwindow/popupwebview.h b/src/lib/popupwindow/popupwebview.h index cf62a5b81..7faf03902 100644 --- a/src/lib/popupwindow/popupwebview.h +++ b/src/lib/popupwindow/popupwebview.h @@ -34,7 +34,8 @@ public: PopupWebPage* webPage(); QWidget* overlayForJsAlert(); - void openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position); + void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, + const QByteArray &data, Qz::NewTabPositionFlag position); signals: diff --git a/src/lib/webview/tabbedwebview.cpp b/src/lib/webview/tabbedwebview.cpp index bfd651135..0172a5222 100644 --- a/src/lib/webview/tabbedwebview.cpp +++ b/src/lib/webview/tabbedwebview.cpp @@ -237,6 +237,16 @@ void TabbedWebView::closeView() emit wantsCloseTab(tabIndex()); } +void TabbedWebView::loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, const QByteArray &data, Qz::NewTabPositionFlag position) +{ + QNetworkRequest r(req); + r.setRawHeader("Referer", url().toEncoded()); + r.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); + + int index = tabWidget()->addView(QUrl(), position); + p_QupZilla->weView(index)->load(r, op, data); +} + void TabbedWebView::contextMenuEvent(QContextMenuEvent* event) { m_menu->clear(); @@ -270,15 +280,6 @@ void TabbedWebView::stop() slotLoadFinished(); } -void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position) -{ - QNetworkRequest req(urla); - req.setRawHeader("Referer", url().toEncoded()); - req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1")); - - tabWidget()->addView(req, position); -} - void TabbedWebView::openNewTab() { tabWidget()->addView(QUrl()); diff --git a/src/lib/webview/tabbedwebview.h b/src/lib/webview/tabbedwebview.h index b0d1f6d4e..d34a58a5d 100644 --- a/src/lib/webview/tabbedwebview.h +++ b/src/lib/webview/tabbedwebview.h @@ -69,7 +69,8 @@ public slots: void userLoadAction(const QUrl &url); void closeView(); - void openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position); + void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, + const QByteArray &data, Qz::NewTabPositionFlag position); void openNewTab(); private slots: diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 6262f7093..b0f589a12 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -196,8 +196,10 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat return; } - const QUrl &searchUrl = mApp->searchEnginesManager()->searchUrl(reqUrl.toString()); - QWebView::load(searchUrl); + SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(reqUrl.toString()); + const QUrl &searchUrl = res.request.url(); + + QWebView::load(res.request, res.operation, res.data); emit urlChanged(searchUrl); m_aboutToLoadUrl = searchUrl; @@ -517,6 +519,11 @@ void WebView::savePageAs() dManager->download(request, info); } +void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position) +{ + loadInNewTab(QNetworkRequest(url), QNetworkAccessManager::GetOperation, QByteArray(), position); +} + void WebView::downloadUrlToDisk() { if (QAction* action = qobject_cast(sender())) { @@ -571,8 +578,8 @@ void WebView::searchSelectedText() } } - const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText()); - openUrlInNewTab(urlToLoad, Qz::NT_SelectedTab); + SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText()); + loadInNewTab(res.request, res.operation, res.data, Qz::NT_SelectedTab); } void WebView::searchSelectedTextInBackgroundTab() @@ -584,8 +591,8 @@ void WebView::searchSelectedTextInBackgroundTab() } } - const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText()); - openUrlInNewTab(urlToLoad, Qz::NT_NotSelectedTab); + SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText()); + loadInNewTab(res.request, res.operation, res.data, Qz::NT_NotSelectedTab); } void WebView::bookmarkLink() diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 1ffc036a3..73c08cb79 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -83,9 +83,12 @@ public slots: void sendPageByMail(); void savePageAs(); + void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position); + virtual void closeView() = 0; - virtual void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position) = 0; virtual void openNewTab() { } + virtual void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, + const QByteArray &data, Qz::NewTabPositionFlag position) = 0; protected slots: void slotLoadStarted();