mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
[UrlLoading] Make sure to correctly load one-word hosts without dot
One-word hosts without the dot may be valid url. So let's try to load it first before using a websearch. Closes #1317
This commit is contained in:
parent
72ab5de448
commit
9502810404
@ -34,7 +34,7 @@ LoadRequest::LoadRequest(const LoadRequest &other)
|
||||
LoadRequest::LoadRequest(const QUrl &url)
|
||||
: m_operation(GetOperation)
|
||||
{
|
||||
m_request.setUrl(url);
|
||||
setUrl(url);
|
||||
}
|
||||
|
||||
LoadRequest::LoadRequest(const QNetworkRequest &req, LoadRequest::Operation op, const QByteArray &data)
|
||||
@ -57,16 +57,6 @@ bool LoadRequest::isEmpty() const
|
||||
return m_request.url().isEmpty();
|
||||
}
|
||||
|
||||
void LoadRequest::load(QWebView* view) const
|
||||
{
|
||||
if (m_operation == GetOperation) {
|
||||
view->load(m_request);
|
||||
}
|
||||
else {
|
||||
view->load(m_request, QNetworkAccessManager::PostOperation, m_data);
|
||||
}
|
||||
}
|
||||
|
||||
QUrl LoadRequest::url() const
|
||||
{
|
||||
return m_request.url();
|
||||
|
@ -40,7 +40,6 @@ public:
|
||||
LoadRequest &operator=(const LoadRequest &other);
|
||||
|
||||
bool isEmpty() const;
|
||||
void load(QWebView* view) const;
|
||||
|
||||
QUrl url() const;
|
||||
void setUrl(const QUrl &url);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "useragentmanager.h"
|
||||
#include "delayedfilewatcher.h"
|
||||
#include "recoverywidget.h"
|
||||
#include "searchenginesmanager.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
#include "schemehandlers/fileschemehandler.h"
|
||||
#include "javascript/externaljsobject.h"
|
||||
@ -462,6 +463,16 @@ void WebPage::dbQuotaExceeded(QWebFrame* frame)
|
||||
frame->securityOrigin().setDatabaseQuota(oldQuota * 2);
|
||||
}
|
||||
|
||||
void WebPage::doWebSearch(const QString &text)
|
||||
{
|
||||
WebView* webView = qobject_cast<WebView*>(view());
|
||||
|
||||
if (webView) {
|
||||
const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(text);
|
||||
webView->load(searchRequest);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QTWEBKIT_2_2
|
||||
void WebPage::appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota)
|
||||
{
|
||||
@ -753,6 +764,12 @@ bool WebPage::extension(Extension extension, const ExtensionOption* option, Exte
|
||||
errorString = tr("Server closed the connection");
|
||||
break;
|
||||
case QNetworkReply::HostNotFoundError:
|
||||
// If a one-word host was not find, search for the text instead
|
||||
// It needs to be async to correctly refresh loading state
|
||||
if (!exOption->url.host().isEmpty() && !exOption->url.host().contains(QL1C('.'))) {
|
||||
QMetaObject::invokeMethod(this, "doWebSearch", Qt::QueuedConnection, Q_ARG(QString, exOption->url.host()));
|
||||
return false;
|
||||
}
|
||||
errorString = tr("Server not found");
|
||||
break;
|
||||
case QNetworkReply::TimeoutError:
|
||||
|
@ -105,6 +105,7 @@ private slots:
|
||||
void windowCloseRequested();
|
||||
|
||||
void dbQuotaExceeded(QWebFrame* frame);
|
||||
void doWebSearch(const QString &text);
|
||||
|
||||
#ifdef USE_QTWEBKIT_2_2
|
||||
void appCacheQuotaExceeded(QWebSecurityOrigin* origin, quint64 originalQuota);
|
||||
|
@ -192,14 +192,24 @@ void WebView::load(const LoadRequest &request)
|
||||
}
|
||||
|
||||
if (reqUrl.isEmpty() || isUrlValid(reqUrl)) {
|
||||
request.load(this);
|
||||
m_aboutToLoadUrl = reqUrl;
|
||||
loadRequest(request);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure to correctly load hosts like localhost (eg. without the dot)
|
||||
if (!reqUrl.isEmpty() &&
|
||||
reqUrl.scheme().isEmpty() &&
|
||||
!reqUrl.path().contains(QL1C(' ')) &&
|
||||
!reqUrl.path().contains(QL1C('.'))
|
||||
) {
|
||||
LoadRequest req = request;
|
||||
req.setUrl(QUrl(QSL("http://") + reqUrl.path()));
|
||||
loadRequest(req);
|
||||
return;
|
||||
}
|
||||
|
||||
const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(reqUrl.toString());
|
||||
m_aboutToLoadUrl = searchRequest.url();
|
||||
searchRequest.load(this);
|
||||
loadRequest(searchRequest);
|
||||
}
|
||||
|
||||
bool WebView::loadingError() const
|
||||
@ -1483,6 +1493,16 @@ void WebView::resizeEvent(QResizeEvent* event)
|
||||
emit viewportResized(page()->viewportSize());
|
||||
}
|
||||
|
||||
void WebView::loadRequest(const LoadRequest &req)
|
||||
{
|
||||
m_aboutToLoadUrl = req.url();
|
||||
|
||||
if (req.operation() == LoadRequest::GetOperation)
|
||||
QWebView::load(req.networkRequest());
|
||||
else
|
||||
QWebView::load(req.networkRequest(), QNetworkAccessManager::PostOperation, req.data());
|
||||
}
|
||||
|
||||
bool WebView::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (s_forceContextMenuOnMouseRelease && obj == this && event->type() == QEvent::ContextMenu) {
|
||||
|
@ -158,6 +158,7 @@ protected:
|
||||
void keyReleaseEvent(QKeyEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
void loadRequest(const LoadRequest &req);
|
||||
void applyZoom();
|
||||
QUrl lastUrl();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user