summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@theqtcompany.com>2015-05-15 15:58:14 +0200
committerPierre Rossi <pierre.rossi@theqtcompany.com>2015-08-19 16:17:00 +0000
commitdc7d93ef5364f82b5131143532b41620d57d9548 (patch)
treeaec019a6a6158317c738530cb20bbe76f9aa55e7 /examples/webenginewidgets
parent13d03ef21d3bd67595bd0b36be7401f6e6bcbbd6 (diff)
Demo browser: add proxy support
And remove NetworkAccessManager-related dead code. Change-Id: I6246aaaa1bbdda43ed0453e7acd0f2df33f58edd Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r--examples/webenginewidgets/browser/browser.pro5
-rw-r--r--examples/webenginewidgets/browser/browserapplication.cpp24
-rw-r--r--examples/webenginewidgets/browser/downloadmanager.cpp1
-rw-r--r--examples/webenginewidgets/browser/networkaccessmanager.cpp160
-rw-r--r--examples/webenginewidgets/browser/networkaccessmanager.h75
-rw-r--r--examples/webenginewidgets/browser/settings.cpp2
-rw-r--r--examples/webenginewidgets/browser/webview.cpp1
7 files changed, 15 insertions, 253 deletions
diff --git a/examples/webenginewidgets/browser/browser.pro b/examples/webenginewidgets/browser/browser.pro
index f54186856..6b31d7ef2 100644
--- a/examples/webenginewidgets/browser/browser.pro
+++ b/examples/webenginewidgets/browser/browser.pro
@@ -62,11 +62,6 @@ SOURCES += \
RESOURCES += data/data.qrc htmls/htmls.qrc
-contains(DEFINES, QWEBENGINEPAGE_SETNETWORKACCESSMANAGER) {
- HEADERS += cookiejar.h networkaccessmanager.h
- SOURCES += cookiejar.cpp networkaccessmanager.cpp
-}
-
build_all:!build_pass {
CONFIG -= build_all
CONFIG += release
diff --git a/examples/webenginewidgets/browser/browserapplication.cpp b/examples/webenginewidgets/browser/browserapplication.cpp
index 5fb8aad4c..84d8a0e3a 100644
--- a/examples/webenginewidgets/browser/browserapplication.cpp
+++ b/examples/webenginewidgets/browser/browserapplication.cpp
@@ -46,7 +46,6 @@
#include "cookiejar.h"
#include "downloadmanager.h"
#include "history.h"
-#include "networkaccessmanager.h"
#include "tabwidget.h"
#include "webview.h"
@@ -299,6 +298,21 @@ void BrowserApplication::loadSettings()
defaultProfile->setPersistentStoragePath(pdataPath);
settings.endGroup();
+
+ settings.beginGroup(QLatin1String("proxy"));
+ QNetworkProxy proxy;
+ if (settings.value(QLatin1String("enabled"), false).toBool()) {
+ if (settings.value(QLatin1String("type"), 0).toInt() == 0)
+ proxy = QNetworkProxy::Socks5Proxy;
+ else
+ proxy = QNetworkProxy::HttpProxy;
+ proxy.setHostName(settings.value(QLatin1String("hostName")).toString());
+ proxy.setPort(settings.value(QLatin1String("port"), 1080).toInt());
+ proxy.setUser(settings.value(QLatin1String("userName")).toString());
+ proxy.setPassword(settings.value(QLatin1String("password")).toString());
+ }
+ QNetworkProxy::setApplicationProxy(proxy);
+ settings.endGroup();
}
QList<BrowserMainWindow*> BrowserApplication::mainWindows()
@@ -474,18 +488,10 @@ DownloadManager *BrowserApplication::downloadManager()
QNetworkAccessManager *BrowserApplication::networkAccessManager()
{
-#if defined(QWEBENGINEPAGE_SETNETWORKACCESSMANAGER)
- if (!s_networkAccessManager) {
- s_networkAccessManager = new NetworkAccessManager();
- s_networkAccessManager->setCookieJar(new CookieJar);
- }
- return s_networkAccessManager;
-#else
if (!s_networkAccessManager) {
s_networkAccessManager = new QNetworkAccessManager();
}
return s_networkAccessManager;
-#endif
}
HistoryManager *BrowserApplication::historyManager()
diff --git a/examples/webenginewidgets/browser/downloadmanager.cpp b/examples/webenginewidgets/browser/downloadmanager.cpp
index 90b0cec9d..eab28942e 100644
--- a/examples/webenginewidgets/browser/downloadmanager.cpp
+++ b/examples/webenginewidgets/browser/downloadmanager.cpp
@@ -43,7 +43,6 @@
#include "autosaver.h"
#include "browserapplication.h"
-#include "networkaccessmanager.h"
#include <math.h>
diff --git a/examples/webenginewidgets/browser/networkaccessmanager.cpp b/examples/webenginewidgets/browser/networkaccessmanager.cpp
deleted file mode 100644
index d2b4f827f..000000000
--- a/examples/webenginewidgets/browser/networkaccessmanager.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "networkaccessmanager.h"
-
-#include "browserapplication.h"
-#include "browsermainwindow.h"
-
-#include <QtCore/QSettings>
-
-#include <QtGui/QDesktopServices>
-#include <QtWidgets/QDialog>
-#include <QtWidgets/QMessageBox>
-#include <QtWidgets/QStyle>
-#include <QtGui/QTextDocument>
-
-#include <QtNetwork/QAuthenticator>
-#include <QtNetwork/QNetworkDiskCache>
-#include <QtNetwork/QNetworkProxy>
-#include <QtNetwork/QNetworkRequest>
-#include <QtNetwork/QNetworkReply>
-#include <QtNetwork/QSslError>
-
-NetworkAccessManager::NetworkAccessManager(QObject *parent)
- : QNetworkAccessManager(parent),
- requestFinishedCount(0), requestFinishedFromCacheCount(0), requestFinishedPipelinedCount(0),
- requestFinishedSecureCount(0), requestFinishedDownloadBufferCount(0)
-{
- connect(this, SIGNAL(finished(QNetworkReply*)),
- SLOT(requestFinished(QNetworkReply*)));
-#ifndef QT_NO_OPENSSL
- connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
- SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
-#endif
- loadSettings();
-
- QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
- QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
- diskCache->setCacheDirectory(location);
- setCache(diskCache);
-}
-
-QNetworkReply* NetworkAccessManager::createRequest(Operation op, const QNetworkRequest & req, QIODevice * outgoingData)
-{
- QNetworkRequest request = req; // copy so we can modify
- // this is a temporary hack until we properly use the pipelining flags from QtWebkit
- // pipeline everything! :)
- request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
- return QNetworkAccessManager::createRequest(op, request, outgoingData);
-}
-
-void NetworkAccessManager::requestFinished(QNetworkReply *reply)
-{
- requestFinishedCount++;
-
- if (reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool() == true)
- requestFinishedFromCacheCount++;
-
- if (reply->attribute(QNetworkRequest::HttpPipeliningWasUsedAttribute).toBool() == true)
- requestFinishedPipelinedCount++;
-
- if (reply->attribute(QNetworkRequest::ConnectionEncryptedAttribute).toBool() == true)
- requestFinishedSecureCount++;
-
- if (reply->attribute(QNetworkRequest::DownloadBufferAttribute).isValid() == true)
- requestFinishedDownloadBufferCount++;
-
- if (requestFinishedCount % 10)
- return;
-
-#ifdef QT_DEBUG
- double pctCached = (double(requestFinishedFromCacheCount) * 100.0/ double(requestFinishedCount));
- double pctPipelined = (double(requestFinishedPipelinedCount) * 100.0/ double(requestFinishedCount));
- double pctSecure = (double(requestFinishedSecureCount) * 100.0/ double(requestFinishedCount));
- double pctDownloadBuffer = (double(requestFinishedDownloadBufferCount) * 100.0/ double(requestFinishedCount));
-
- qDebug("STATS [%lli requests total] [%3.2f%% from cache] [%3.2f%% pipelined] [%3.2f%% SSL/TLS] [%3.2f%% Zerocopy]", requestFinishedCount, pctCached, pctPipelined, pctSecure, pctDownloadBuffer);
-#endif
-}
-
-void NetworkAccessManager::loadSettings()
-{
- QSettings settings;
- settings.beginGroup(QLatin1String("proxy"));
- QNetworkProxy proxy;
- if (settings.value(QLatin1String("enabled"), false).toBool()) {
- if (settings.value(QLatin1String("type"), 0).toInt() == 0)
- proxy = QNetworkProxy::Socks5Proxy;
- else
- proxy = QNetworkProxy::HttpProxy;
- proxy.setHostName(settings.value(QLatin1String("hostName")).toString());
- proxy.setPort(settings.value(QLatin1String("port"), 1080).toInt());
- proxy.setUser(settings.value(QLatin1String("userName")).toString());
- proxy.setPassword(settings.value(QLatin1String("password")).toString());
- }
- setProxy(proxy);
-}
-
-#ifndef QT_NO_OPENSSL
-void NetworkAccessManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &error)
-{
- // check if SSL certificate has been trusted already
- QString replyHost = reply->url().host() + QString(":%1").arg(reply->url().port());
- if (! sslTrustedHostList.contains(replyHost)) {
- BrowserMainWindow *mainWindow = BrowserApplication::instance()->mainWindow();
-
- QStringList errorStrings;
- for (int i = 0; i < error.count(); ++i)
- errorStrings += error.at(i).errorString();
- QString errors = errorStrings.join(QLatin1String("\n"));
- int ret = QMessageBox::warning(mainWindow, QCoreApplication::applicationName(),
- tr("SSL Errors:\n\n%1\n\n%2\n\n"
- "Do you want to ignore these errors for this host?").arg(reply->url().toString()).arg(errors),
- QMessageBox::Yes | QMessageBox::No,
- QMessageBox::No);
- if (ret == QMessageBox::Yes) {
- reply->ignoreSslErrors();
- sslTrustedHostList.append(replyHost);
- }
- }
-}
-#endif
diff --git a/examples/webenginewidgets/browser/networkaccessmanager.h b/examples/webenginewidgets/browser/networkaccessmanager.h
deleted file mode 100644
index f3ee2d338..000000000
--- a/examples/webenginewidgets/browser/networkaccessmanager.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the demonstration applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef NETWORKACCESSMANAGER_H
-#define NETWORKACCESSMANAGER_H
-
-#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkRequest>
-
-class NetworkAccessManager : public QNetworkAccessManager
-{
- Q_OBJECT
-
-public:
- NetworkAccessManager(QObject *parent = 0);
-
- virtual QNetworkReply* createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 );
-
-private:
- QList<QString> sslTrustedHostList;
- qint64 requestFinishedCount;
- qint64 requestFinishedFromCacheCount;
- qint64 requestFinishedPipelinedCount;
- qint64 requestFinishedSecureCount;
- qint64 requestFinishedDownloadBufferCount;
-
-public slots:
- void loadSettings();
- void requestFinished(QNetworkReply *reply);
-
-private slots:
-#ifndef QT_NO_OPENSSL
- void sslErrors(QNetworkReply *reply, const QList<QSslError> &error);
-#endif
-};
-
-#endif // NETWORKACCESSMANAGER_H
diff --git a/examples/webenginewidgets/browser/settings.cpp b/examples/webenginewidgets/browser/settings.cpp
index ee8c719b4..35e5e26c9 100644
--- a/examples/webenginewidgets/browser/settings.cpp
+++ b/examples/webenginewidgets/browser/settings.cpp
@@ -47,7 +47,6 @@
#include "cookiejar.h"
#endif
#include "history.h"
-#include "networkaccessmanager.h"
#include "webview.h"
#include <QtCore/QLocale>
@@ -240,7 +239,6 @@ void SettingsDialog::saveToSettings()
BrowserApplication::instance()->loadSettings();
#if defined(QWEBENGINEPAGE_SETNETWORKACCESSMANAGER)
- BrowserApplication::networkAccessManager()->loadSettings();
BrowserApplication::cookieJar()->loadSettings();
#endif
BrowserApplication::historyManager()->loadSettings();
diff --git a/examples/webenginewidgets/browser/webview.cpp b/examples/webenginewidgets/browser/webview.cpp
index 7705e7ab4..00ec40874 100644
--- a/examples/webenginewidgets/browser/webview.cpp
+++ b/examples/webenginewidgets/browser/webview.cpp
@@ -44,7 +44,6 @@
#include "cookiejar.h"
#include "downloadmanager.h"
#include "featurepermissionbar.h"
-#include "networkaccessmanager.h"
#include "ui_passworddialog.h"
#include "ui_proxy.h"
#include "tabwidget.h"