diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index f9df7710bc7246d848dafccfa26e2f6001c3b050..4949240543fe53097d3f3c2349ac42f7a77d83d4 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 2c28c082024edfbcf2a0dd8528d7032a1829205b..14e386a3405394d82ec66c4bd778c3dd13422ad1 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 0000000000000000000000000000000000000000..9db76e9101b9e2b480595e49faf0539a872ba0e4 --- /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 0000000000000000000000000000000000000000..5580de598bb445db89ed944ea7ff77201f6f3ca0 --- /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 8247e07eb3b6b83fe9e345788e1b276ac387a517..da0dd8ab3ee09aefb865c9975643fae052142bec 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());