summaryrefslogtreecommitdiffstats
path: root/src/core/proxy_config_service_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/proxy_config_service_qt.cpp')
-rw-r--r--src/core/proxy_config_service_qt.cpp90
1 files changed, 58 insertions, 32 deletions
diff --git a/src/core/proxy_config_service_qt.cpp b/src/core/proxy_config_service_qt.cpp
index fed3da7f5..48f3593e6 100644
--- a/src/core/proxy_config_service_qt.cpp
+++ b/src/core/proxy_config_service_qt.cpp
@@ -36,6 +36,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
+
+//================ Based on ChromeProxyConfigService =======================
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -60,17 +63,16 @@ net::ProxyServer ProxyConfigServiceQt::fromQNetworkProxy(const QNetworkProxy &qt
proxyScheme = net::ProxyServer::SCHEME_HTTP;
break;
case QNetworkProxy::NoProxy:
- default:
+ case QNetworkProxy::DefaultProxy:
proxyScheme = net::ProxyServer::SCHEME_DIRECT;
break;
}
return net::ProxyServer(proxyScheme, net::HostPortPair(qtProxy.hostName().toStdString(), qtProxy.port()));
}
-//================ Based on ChromeProxyConfigService =======================
-
ProxyConfigServiceQt::ProxyConfigServiceQt(std::unique_ptr<ProxyConfigService> baseService)
: m_baseService(baseService.release()),
+ m_usesSystemConfiguration(false),
m_registeredObserver(false)
{
}
@@ -83,7 +85,6 @@ ProxyConfigServiceQt::~ProxyConfigServiceQt()
void ProxyConfigServiceQt::AddObserver(net::ProxyConfigService::Observer *observer)
{
- RegisterObserver();
m_observers.AddObserver(observer);
}
@@ -94,26 +95,31 @@ void ProxyConfigServiceQt::RemoveObserver(net::ProxyConfigService::Observer *obs
net::ProxyConfigService::ConfigAvailability ProxyConfigServiceQt::GetLatestProxyConfig(net::ProxyConfig *config)
{
- RegisterObserver();
-
- // Ask the base service if available.
- net::ProxyConfig systemConfig;
- ConfigAvailability systemAvailability = net::ProxyConfigService::CONFIG_UNSET;
- if (m_baseService.get())
- systemAvailability = m_baseService->GetLatestProxyConfig(&systemConfig);
+#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
+ m_usesSystemConfiguration = QNetworkProxyFactory::usesSystemConfiguration();
+#endif
+ if (m_usesSystemConfiguration) {
+ // Use Chromium's base service to retrieve system settings
+ net::ProxyConfig systemConfig;
+ ConfigAvailability systemAvailability = net::ProxyConfigService::CONFIG_UNSET;
+ if (m_baseService.get())
+ systemAvailability = m_baseService->GetLatestProxyConfig(&systemConfig);
+ *config = systemConfig;
+ // make sure to get updates via OnProxyConfigChanged
+ RegisterObserver();
+ return systemAvailability;
+ }
+ // Use QNetworkProxy::applicationProxy settings
const QNetworkProxy &qtProxy = QNetworkProxy::applicationProxy();
if (qtProxy == m_qtApplicationProxy && !m_qtProxyConfig.proxy_rules().empty()) {
+ // no changes
*config = m_qtProxyConfig;
return CONFIG_VALID;
}
+
m_qtApplicationProxy = qtProxy;
m_qtProxyConfig = net::ProxyConfig();
- if (qtProxy.type() == QNetworkProxy::NoProxy
- && QNetworkProxyFactory::usesSystemConfiguration()) {
- *config = systemConfig;
- return systemAvailability;
- }
net::ProxyConfig::ProxyRules qtRules;
net::ProxyServer server = fromQNetworkProxy(qtProxy);
@@ -143,31 +149,51 @@ net::ProxyConfigService::ConfigAvailability ProxyConfigServiceQt::GetLatestProxy
void ProxyConfigServiceQt::OnLazyPoll()
{
- if (m_qtApplicationProxy != QNetworkProxy::applicationProxy()) {
- net::ProxyConfig unusedConfig;
- OnProxyConfigChanged(unusedConfig, CONFIG_VALID);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
+ // We need to update if
+ // - setUseSystemConfiguration() was called in between
+ // - user changed application proxy
+ if (m_usesSystemConfiguration != QNetworkProxyFactory::usesSystemConfiguration()
+ || (!m_usesSystemConfiguration && m_qtApplicationProxy != QNetworkProxy::applicationProxy())) {
+ Update();
+ } else if (m_usesSystemConfiguration) {
+ if (m_baseService.get())
+ m_baseService->OnLazyPoll();
}
- if (m_baseService.get())
- m_baseService->OnLazyPoll();
+#else
+ if (m_qtApplicationProxy != QNetworkProxy::applicationProxy())
+ Update();
+#endif
}
-
+// Called when the base service changed
void ProxyConfigServiceQt::OnProxyConfigChanged(const net::ProxyConfig &config, ConfigAvailability availability)
{
- Q_UNUSED(config);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ Q_UNUSED(config);
- if (m_qtApplicationProxy != QNetworkProxy::applicationProxy()
- || m_qtApplicationProxy.type() == QNetworkProxy::NoProxy) {
- net::ProxyConfig actual_config;
- availability = GetLatestProxyConfig(&actual_config);
- if (availability == CONFIG_PENDING)
- return;
- for (net::ProxyConfigService::Observer &observer: m_observers)
- observer.OnProxyConfigChanged(actual_config, availability);
- }
+ if (!m_usesSystemConfiguration)
+ return;
+
+ Update();
+}
+
+// Update our observers
+void ProxyConfigServiceQt::Update()
+{
+ net::ProxyConfig actual_config;
+ ConfigAvailability availability = GetLatestProxyConfig(&actual_config);
+ if (availability == CONFIG_PENDING)
+ return;
+ for (net::ProxyConfigService::Observer &observer: m_observers)
+ observer.OnProxyConfigChanged(actual_config, availability);
}
+// Register ourselves as observer of the base service.
+// This has to be done on the IO thread, and therefore cannot be done
+// in the constructor.
void ProxyConfigServiceQt::RegisterObserver()
{
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));