summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@theqtcompany.com>2015-05-21 17:28:44 +0200
committerPierre Rossi <pierre.rossi@theqtcompany.com>2015-06-08 11:17:33 +0000
commit0e006b8ea755ebad01faf3e747e61abdf158289a (patch)
tree28fbc979b8576fa6c22044785e6c59d8f1048252 /src
parent8c3178b64d992435cb90a426ff075fee6778e04a (diff)
Introduce ProxyResolverQt
This allows using QtNetwork's proxy auto conf detection code from QNetworkProxyFactory, by setting the QTWEBENGINE_USE_QT_PROXYRESOLVER environment variable. Otherwise, we still rely on chromium's implementation. Task-number: QTBUG-45376 Change-Id: I7b8b77c932060ad36090d388d616b713d93cad0a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/core_gyp_generator.pro2
-rw-r--r--src/core/proxy_config_service_qt.cpp14
-rw-r--r--src/core/proxy_resolver_qt.cpp93
-rw-r--r--src/core/proxy_resolver_qt.h62
-rw-r--r--src/core/url_request_context_getter_qt.cpp8
5 files changed, 177 insertions, 2 deletions
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro
index f9df7710b..494924054 100644
--- a/src/core/core_gyp_generator.pro
+++ b/src/core/core_gyp_generator.pro
@@ -59,6 +59,7 @@ SOURCES = \
ozone_platform_eglfs.cpp \
process_main.cpp \
proxy_config_service_qt.cpp \
+ proxy_resolver_qt.cpp \
qrc_protocol_handler_qt.cpp \
qt_render_view_observer_host.cpp \
render_widget_host_view_qt.cpp \
@@ -128,6 +129,7 @@ HEADERS = \
ozone_platform_eglfs.h \
process_main.h \
proxy_config_service_qt.h \
+ proxy_resolver_qt.h \
qrc_protocol_handler_qt.h \
qt_render_view_observer_host.h \
qtwebenginecoreglobal.h \
diff --git a/src/core/proxy_config_service_qt.cpp b/src/core/proxy_config_service_qt.cpp
index 2c28c0820..14e386a34 100644
--- a/src/core/proxy_config_service_qt.cpp
+++ b/src/core/proxy_config_service_qt.cpp
@@ -39,6 +39,8 @@
#include "proxy_config_service_qt.h"
+#include "proxy_resolver_qt.h"
+
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
@@ -105,9 +107,15 @@ net::ProxyConfigService::ConfigAvailability ProxyConfigServiceQt::GetLatestProxy
return CONFIG_VALID;
}
m_qtApplicationProxy = qtProxy;
- m_qtProxyConfig = net::ProxyConfig();
+ m_qtProxyConfig = (systemAvailability == CONFIG_VALID) ? systemConfig : net::ProxyConfig();
+ const bool useProxyResolver = ProxyResolverQt::useProxyResolverQt();
+
if (qtProxy.type() == QNetworkProxy::NoProxy) {
*config = systemConfig;
+ if (useProxyResolver) {
+ config->set_auto_detect(true);
+ config->set_pac_mandatory(true);
+ }
return systemAvailability;
}
@@ -132,6 +140,10 @@ net::ProxyConfigService::ConfigAvailability ProxyConfigServiceQt::GetLatestProxy
}
m_qtProxyConfig.proxy_rules() = qtRules;
+ if (useProxyResolver) {
+ m_qtProxyConfig.set_pac_mandatory(true);
+ m_qtProxyConfig.set_auto_detect(true);
+ }
*config = m_qtProxyConfig;
return CONFIG_VALID;
}
diff --git a/src/core/proxy_resolver_qt.cpp b/src/core/proxy_resolver_qt.cpp
new file mode 100644
index 000000000..9db76e910
--- /dev/null
+++ b/src/core/proxy_resolver_qt.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module 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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later 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 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "proxy_resolver_qt.h"
+
+#include "proxy_config_service_qt.h"
+#include "type_conversion.h"
+
+#include "net/base/load_states.h"
+#include "net/base/net_errors.h"
+#include "net/proxy/proxy_info.h"
+
+#include <QNetworkProxyFactory>
+#include <QNetworkProxyQuery>
+
+ProxyResolverQt::ProxyResolverQt()
+ : net::ProxyResolver(/*expects_pac_bytes = */ false)
+{
+}
+
+int ProxyResolverQt::GetProxyForURL(const GURL &url, net::ProxyInfo *results, const net::CompletionCallback &, net::ProxyResolver::RequestHandle *, const net::BoundNetLog &)
+{
+ QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(QNetworkProxyQuery(QtWebEngineCore::toQt(url)));
+ if (proxies.empty())
+ return net::ERR_FAILED;
+ if (proxies.size() == 1) {
+ const QNetworkProxy &qtProxy = proxies.first();
+ if (qtProxy.type() == QNetworkProxy::NoProxy)
+ results->UseDirect();
+ else
+ results->UseProxyServer(ProxyConfigServiceQt::fromQNetworkProxy(qtProxy));
+ return net::OK;
+ }
+ net::ProxyList proxyList;
+ Q_FOREACH (const QNetworkProxy &qtProxy, proxies)
+ proxyList.AddProxyServer(ProxyConfigServiceQt::fromQNetworkProxy(qtProxy));
+ results->UseProxyList(proxyList);
+ return net::OK;
+}
+
+void ProxyResolverQt::CancelRequest(net::ProxyResolver::RequestHandle)
+{
+ // This is a synchronous ProxyResolver; no possibility for async requests.
+ NOTREACHED();
+}
+
+net::LoadState ProxyResolverQt::GetLoadState(net::ProxyResolver::RequestHandle) const
+{
+ NOTREACHED();
+ return net::LOAD_STATE_IDLE;
+}
+
+void ProxyResolverQt::CancelSetPacScript()
+{
+ NOTREACHED();
+}
+
+int ProxyResolverQt::SetPacScript(const scoped_refptr<net::ProxyResolverScriptData> &, const net::CompletionCallback &) {
+ return net::OK;
+}
diff --git a/src/core/proxy_resolver_qt.h b/src/core/proxy_resolver_qt.h
new file mode 100644
index 000000000..5580de598
--- /dev/null
+++ b/src/core/proxy_resolver_qt.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module 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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later 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 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PROXY_RESOLVER_QT_H
+#define PROXY_RESOLVER_QT_H
+
+#include "net/proxy/proxy_resolver.h"
+#include <qglobal.h>
+
+
+class ProxyResolverQt : public net::ProxyResolver {
+public:
+ static bool useProxyResolverQt() { return qEnvironmentVariableIsSet("QTWEBENGINE_USE_QT_PROXYRESOLVER"); }
+
+ ProxyResolverQt();
+
+ int GetProxyForURL(const GURL &url, net::ProxyInfo *results, const net::CompletionCallback &
+ , RequestHandle*, const net::BoundNetLog&) override;
+
+ void CancelRequest(RequestHandle) override;
+
+ net::LoadState GetLoadState(RequestHandle) const override;
+
+ void CancelSetPacScript() override;
+
+ int SetPacScript(const scoped_refptr<net::ProxyResolverScriptData>& /*script_data*/, const net::CompletionCallback& /*callback*/) override;
+};
+
+#endif // PROXY_RESOLVER_QT_H
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index 8247e07eb..da0dd8ab3 100644
--- a/src/core/url_request_context_getter_qt.cpp
+++ b/src/core/url_request_context_getter_qt.cpp
@@ -67,6 +67,7 @@
#include "content_client_qt.h"
#include "network_delegate_qt.h"
#include "proxy_config_service_qt.h"
+#include "proxy_resolver_qt.h"
#include "qrc_protocol_handler_qt.h"
#include "type_conversion.h"
@@ -150,7 +151,12 @@ void URLRequestContextGetterQt::generateStorage()
base::WorkerPool::GetTaskRunner(true)));
m_storage->set_cert_verifier(net::CertVerifier::CreateDefault());
- m_storage->set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, 0, NULL));
+ net::ProxyService *proxyService = nullptr;
+ if (ProxyResolverQt::useProxyResolverQt())
+ proxyService = new net::ProxyService(proxyConfigService, new ProxyResolverQt, nullptr);
+ else
+ proxyService = net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, /*num_pac_threads = */0 /*default*/, NULL);
+ m_storage->set_proxy_service(proxyService);
m_storage->set_ssl_config_service(new net::SSLConfigServiceDefaults);
m_storage->set_transport_security_state(new net::TransportSecurityState());