diff --git a/src/lib/webkit/loadrequest.cpp b/src/lib/webkit/loadrequest.cpp index 51d324a54..ee51f45aa 100644 --- a/src/lib/webkit/loadrequest.cpp +++ b/src/lib/webkit/loadrequest.cpp @@ -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(); diff --git a/src/lib/webkit/loadrequest.h b/src/lib/webkit/loadrequest.h index cf009b553..a9fd0412e 100644 --- a/src/lib/webkit/loadrequest.h +++ b/src/lib/webkit/loadrequest.h @@ -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); diff --git a/src/lib/webkit/webpage.cpp b/src/lib/webkit/webpage.cpp index 5c84df759..f4e7d83a0 100644 --- a/src/lib/webkit/webpage.cpp +++ b/src/lib/webkit/webpage.cpp @@ -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(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: diff --git a/src/lib/webkit/webpage.h b/src/lib/webkit/webpage.h index a9d042cb1..8190ff037 100644 --- a/src/lib/webkit/webpage.h +++ b/src/lib/webkit/webpage.h @@ -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); diff --git a/src/lib/webkit/webview.cpp b/src/lib/webkit/webview.cpp index 3c26d036f..45b6cb9db 100644 --- a/src/lib/webkit/webview.cpp +++ b/src/lib/webkit/webview.cpp @@ -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) { diff --git a/src/lib/webkit/webview.h b/src/lib/webkit/webview.h index 81335a04c..c64c06bcc 100644 --- a/src/lib/webkit/webview.h +++ b/src/lib/webkit/webview.h @@ -158,6 +158,7 @@ protected: void keyReleaseEvent(QKeyEvent* event); void resizeEvent(QResizeEvent* event); + void loadRequest(const LoadRequest &req); void applyZoom(); QUrl lastUrl();