summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets/simplebrowser/webview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets/simplebrowser/webview.cpp')
-rw-r--r--examples/webenginewidgets/simplebrowser/webview.cpp55
1 files changed, 10 insertions, 45 deletions
diff --git a/examples/webenginewidgets/simplebrowser/webview.cpp b/examples/webenginewidgets/simplebrowser/webview.cpp
index d2a38523f..657993fc6 100644
--- a/examples/webenginewidgets/simplebrowser/webview.cpp
+++ b/examples/webenginewidgets/simplebrowser/webview.cpp
@@ -48,7 +48,6 @@
#include <QDebug>
#include <QMenu>
#include <QMessageBox>
-#include <QNetworkReply>
#include <QTimer>
WebView::WebView(QWidget *parent)
@@ -60,11 +59,10 @@ WebView::WebView(QWidget *parent)
});
connect(this, &QWebEngineView::loadFinished, [this](bool success) {
if (!success) {
- qWarning() << "Could not load page: " << url();
m_loadProgress = 0;
}
});
- connect(this, &QWebEngineView::iconUrlChanged, this, &WebView::handleIconUrlChanged);
+
connect(this, &QWebEngineView::renderProcessTerminated,
[this](QWebEnginePage::RenderProcessTerminationStatus termStatus, int statusCode) {
QString status;
@@ -82,8 +80,11 @@ WebView::WebView(QWidget *parent)
status = tr("Render process killed");
break;
}
- QMessageBox::critical(window(), status, tr("Render process exited with code: %1").arg(statusCode));
- QTimer::singleShot(0, [this] { reload(); });
+ QMessageBox::StandardButton btn = QMessageBox::question(window(), status,
+ tr("Render process exited with code: %1\n"
+ "Do you want to reload the page ?").arg(statusCode));
+ if (btn == QMessageBox::Yes)
+ QTimer::singleShot(0, [this] { reload(); });
});
}
@@ -96,13 +97,6 @@ void WebView::setPage(WebPage *page)
QWebEngineView::setPage(page);
}
-QIcon WebView::icon() const
-{
- if (!m_icon.isNull())
- return m_icon;
- return QIcon(QLatin1String(":defaulticon.png"));
-}
-
int WebView::loadProgress() const
{
return m_loadProgress;
@@ -121,12 +115,6 @@ bool WebView::isWebActionEnabled(QWebEnginePage::WebAction webAction) const
return page()->action(webAction)->isEnabled();
}
-QNetworkAccessManager &WebView::networkAccessManager()
-{
- static QNetworkAccessManager networkAccessManager;
- return networkAccessManager;
-}
-
QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)
{
switch (type) {
@@ -134,6 +122,10 @@ QWebEngineView *WebView::createWindow(QWebEnginePage::WebWindowType type)
BrowserWindow *mainWindow = qobject_cast<BrowserWindow*>(window());
return mainWindow->tabWidget()->createTab();
}
+ case QWebEnginePage::WebBrowserBackgroundTab: {
+ BrowserWindow *mainWindow = qobject_cast<BrowserWindow*>(window());
+ return mainWindow->tabWidget()->createTab(false);
+ }
case QWebEnginePage::WebBrowserWindow: {
BrowserWindow *mainWindow = new BrowserWindow();
Browser::instance().addWindow(mainWindow);
@@ -163,30 +155,3 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
menu->popup(event->globalPos());
}
-void WebView::handleIconUrlChanged(const QUrl &url)
-{
- QNetworkRequest iconRequest(url);
-#ifndef QT_NO_OPENSSL
- QSslConfiguration conf = iconRequest.sslConfiguration();
- conf.setPeerVerifyMode(QSslSocket::VerifyNone);
- iconRequest.setSslConfiguration(conf);
-#endif
- QNetworkReply *iconReply = networkAccessManager().get(iconRequest);
- iconReply->setParent(this);
- connect(iconReply, &QNetworkReply::finished, this, &WebView::handleIconLoaded);
-}
-
-void WebView::handleIconLoaded()
-{
- QNetworkReply *iconReply = qobject_cast<QNetworkReply*>(sender());
- if (iconReply && iconReply->error() == QNetworkReply::NoError) {
- QByteArray data = iconReply->readAll();
- QPixmap pixmap;
- pixmap.loadFromData(data);
- m_icon.addPixmap(pixmap);
- iconReply->deleteLater();
- } else {
- m_icon = QIcon(QStringLiteral(":defaulticon.png"));
- }
- emit iconChanged(m_icon);
-}