summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-10-17 19:28:27 +0200
committerMichal Klocek <michal.klocek@qt.io>2019-02-04 15:33:44 +0000
commit740922cc2d7a9b90956d2cf7923c996d79e98a2a (patch)
treedacc532ba7d06f48a6700b2d0b09a0df1f2386da /src
parent17cc1a0cbe37ac33200012eb49c17e3b48c90a55 (diff)
Add proxy switches handling
This change adds switches for proxy: https://www.chromium.org/developers/design-documents/network-settings [ChangeLog] Uses proxy switches for initial proxy configuration Fixes: QTBUG-71229 Change-Id: I1bc02f20c20d737234c650a18f0e0f7c1c63a464 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/command_line_pref_store_qt.cpp90
-rw-r--r--src/core/command_line_pref_store_qt.h56
-rw-r--r--src/core/core_chromium.pri2
-rw-r--r--src/core/net/proxy_config_service_qt.cpp14
-rw-r--r--src/core/net/proxy_config_service_qt.h10
-rw-r--r--src/core/profile_io_data_qt.cpp8
-rw-r--r--src/core/profile_qt.cpp7
-rw-r--r--src/core/qtwebengine.gni1
-rw-r--r--src/core/web_engine_context.cpp56
-rw-r--r--src/core/web_engine_context.h2
10 files changed, 219 insertions, 27 deletions
diff --git a/src/core/command_line_pref_store_qt.cpp b/src/core/command_line_pref_store_qt.cpp
new file mode 100644
index 000000000..5c5c82e1a
--- /dev/null
+++ b/src/core/command_line_pref_store_qt.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Copyright (c) 2012 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.
+
+#include "command_line_pref_store_qt.h"
+
+#include "chrome/common/chrome_switches.h"
+#include "components/proxy_config/proxy_config_dictionary.h"
+#include "components/proxy_config/proxy_config_pref_names.h"
+#include "content/public/common/content_switches.h"
+#include <QDebug>
+
+CommandLinePrefStoreQt::CommandLinePrefStoreQt(const base::CommandLine *commandLine)
+ : CommandLinePrefStore(commandLine)
+{
+
+ if (commandLine->HasSwitch(switches::kNoProxyServer)) {
+ SetValue(proxy_config::prefs::kProxy,
+ std::make_unique<base::Value>(ProxyConfigDictionary::CreateDirect()),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ } else if (commandLine->HasSwitch(switches::kProxyPacUrl)) {
+ std::string pac_script_url =
+ commandLine->GetSwitchValueASCII(switches::kProxyPacUrl);
+ SetValue(proxy_config::prefs::kProxy,
+ std::make_unique<base::Value>(ProxyConfigDictionary::CreatePacScript(
+ pac_script_url, false)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ } else if (commandLine->HasSwitch(switches::kProxyAutoDetect)) {
+ SetValue(proxy_config::prefs::kProxy,
+ std::make_unique<base::Value>(
+ ProxyConfigDictionary::CreateAutoDetect()),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ } else if (commandLine->HasSwitch(switches::kProxyServer)) {
+ std::string proxy_server =
+ commandLine->GetSwitchValueASCII(switches::kProxyServer);
+ std::string bypass_list =
+ commandLine->GetSwitchValueASCII(switches::kProxyBypassList);
+ SetValue(
+ proxy_config::prefs::kProxy,
+ std::make_unique<base::Value>(ProxyConfigDictionary::CreateFixedServers(
+ proxy_server, bypass_list)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ }
+
+ if (commandLine->HasSwitch(switches::kNoProxyServer) && (commandLine->HasSwitch(switches::kProxyAutoDetect) || commandLine->HasSwitch(switches::kProxyServer) || commandLine->HasSwitch(switches::kProxyPacUrl) || commandLine->HasSwitch(switches::kProxyBypassList))) {
+ qWarning("Additional command-line proxy switches specified when --%s was also specified",
+ qPrintable(switches::kNoProxyServer));
+ }
+}
+
+CommandLinePrefStoreQt::~CommandLinePrefStoreQt() = default;
diff --git a/src/core/command_line_pref_store_qt.h b/src/core/command_line_pref_store_qt.h
new file mode 100644
index 000000000..a509f8ca9
--- /dev/null
+++ b/src/core/command_line_pref_store_qt.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COMMAND_LINE_PREF_STORE_QT_H
+#define COMMAND_LINE_PREF_STORE_QT_H
+
+#include "base/command_line.h"
+#include "components/prefs/command_line_pref_store.h"
+
+class CommandLinePrefStoreQt : public CommandLinePrefStore
+{
+public:
+ explicit CommandLinePrefStoreQt(const base::CommandLine *commandLine);
+
+protected:
+ ~CommandLinePrefStoreQt() override;
+ DISALLOW_COPY_AND_ASSIGN(CommandLinePrefStoreQt);
+};
+
+#endif // COMMAND_LINE_PREF_STORE_QT_H
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index 3918dc0aa..2b6c2534c 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -53,6 +53,7 @@ SOURCES = \
clipboard_qt.cpp \
color_chooser_qt.cpp \
color_chooser_controller.cpp \
+ command_line_pref_store_qt.cpp \
common/qt_ipc_logging.cpp \
common/qt_messages.cpp \
common/user_script_data.cpp \
@@ -150,6 +151,7 @@ HEADERS = \
client_cert_override_p.h \
client_cert_select_controller.h \
clipboard_qt.h \
+ command_line_pref_store_qt.h \
color_chooser_qt.h \
color_chooser_controller_p.h \
color_chooser_controller.h \
diff --git a/src/core/net/proxy_config_service_qt.cpp b/src/core/net/proxy_config_service_qt.cpp
index 13b969281..ff8ab20aa 100644
--- a/src/core/net/proxy_config_service_qt.cpp
+++ b/src/core/net/proxy_config_service_qt.cpp
@@ -47,6 +47,7 @@
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
+#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
using content::BrowserThread;
@@ -68,10 +69,13 @@ net::ProxyServer ProxyConfigServiceQt::fromQNetworkProxy(const QNetworkProxy &qt
}
}
-ProxyConfigServiceQt::ProxyConfigServiceQt(std::unique_ptr<ProxyConfigService> baseService)
+ProxyConfigServiceQt::ProxyConfigServiceQt(std::unique_ptr<ProxyConfigService> baseService,
+ const net::ProxyConfigWithAnnotation& initialConfig, ProxyPrefs::ConfigState initialState)
: m_baseService(baseService.release()),
m_usesSystemConfiguration(false),
- m_registeredObserver(false)
+ m_registeredObserver(false),
+ m_prefConfig(initialConfig),
+ m_perfState(initialState)
{
}
@@ -100,8 +104,10 @@ net::ProxyConfigService::ConfigAvailability ProxyConfigServiceQt::GetLatestProxy
ConfigAvailability systemAvailability = net::ProxyConfigService::CONFIG_UNSET;
if (m_baseService.get())
systemAvailability = m_baseService->GetLatestProxyConfig(&systemConfig);
- *config = systemConfig;
- // make sure to get updates via OnProxyConfigChanged
+ ProxyPrefs::ConfigState configState;
+ systemAvailability = PrefProxyConfigTrackerImpl::GetEffectiveProxyConfig(
+ m_perfState, m_prefConfig, systemAvailability, systemConfig,
+ false, &configState, config);
RegisterObserver();
return systemAvailability;
}
diff --git a/src/core/net/proxy_config_service_qt.h b/src/core/net/proxy_config_service_qt.h
index 961927b89..09e88d445 100644
--- a/src/core/net/proxy_config_service_qt.h
+++ b/src/core/net/proxy_config_service_qt.h
@@ -43,8 +43,10 @@
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
+#include "net/proxy_resolution/proxy_config.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/proxy_resolution/proxy_config_with_annotation.h"
+#include "components/proxy_config/proxy_prefs.h"
#include <QNetworkProxy>
@@ -55,7 +57,9 @@ public:
static net::ProxyServer fromQNetworkProxy(const QNetworkProxy &);
- explicit ProxyConfigServiceQt(std::unique_ptr<ProxyConfigService> baseService);
+ explicit ProxyConfigServiceQt(std::unique_ptr<ProxyConfigService> baseService,
+ const net::ProxyConfigWithAnnotation& initialConfig,
+ ProxyPrefs::ConfigState initialState);
~ProxyConfigServiceQt() override;
// ProxyConfigService implementation:
@@ -86,6 +90,10 @@ private:
// Indicates whether the base service registration is done.
bool m_registeredObserver;
+ // Configuration as defined by prefs.
+ net::ProxyConfigWithAnnotation m_prefConfig;
+ ProxyPrefs::ConfigState m_perfState;
+
DISALLOW_COPY_AND_ASSIGN(ProxyConfigServiceQt);
};
diff --git a/src/core/profile_io_data_qt.cpp b/src/core/profile_io_data_qt.cpp
index 20754ed7a..55d3bba5a 100644
--- a/src/core/profile_io_data_qt.cpp
+++ b/src/core/profile_io_data_qt.cpp
@@ -49,6 +49,7 @@
#include "content/public/common/content_features.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
+#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_log_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
@@ -640,10 +641,15 @@ void ProfileIODataQt::updateStorageSettings()
// must synchronously run on the glib message loop. This will be passed to
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
Q_ASSERT(m_proxyConfigService == 0);
+ net::ProxyConfigWithAnnotation initialConfig;
+ ProxyPrefs::ConfigState initialConfigState = PrefProxyConfigTrackerImpl::ReadPrefConfig(
+ m_profileAdapter->profile()->GetPrefs(), &initialConfig);
+
m_proxyConfigService =
new ProxyConfigServiceQt(
net::ProxyResolutionService::CreateSystemProxyConfigService(
- base::CreateSingleThreadTaskRunnerWithTraits({content::BrowserThread::IO})));
+ base::CreateSingleThreadTaskRunnerWithTraits({content::BrowserThread::IO})),
+ initialConfig, initialConfigState);
//pass interface to io thread
m_proxyResolverFactoryInterface = ChromeMojoProxyResolverFactory::CreateWithStrongBinding().PassInterface();
if (m_initialized)
diff --git a/src/core/profile_qt.cpp b/src/core/profile_qt.cpp
index e4698c677..d98bb5c9c 100644
--- a/src/core/profile_qt.cpp
+++ b/src/core/profile_qt.cpp
@@ -41,6 +41,7 @@
#include "profile_adapter.h"
#include "browsing_data_remover_delegate_qt.h"
+#include "command_line_pref_store_qt.h"
#include "download_manager_delegate_qt.h"
#include "net/ssl_host_state_delegate_qt.h"
#include "net/url_request_context_getter_qt.h"
@@ -48,6 +49,7 @@
#include "qtwebenginecoreglobal_p.h"
#include "type_conversion.h"
#include "web_engine_library_info.h"
+#include "web_engine_context.h"
#include "base/time/time.h"
#include "content/public/browser/browser_thread.h"
@@ -62,6 +64,7 @@
#include "components/prefs/pref_service_factory.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/user_prefs/user_prefs.h"
+#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
#if QT_CONFIG(webengine_spellchecker)
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/common/pref_names.h"
@@ -76,8 +79,10 @@ ProfileQt::ProfileQt(ProfileAdapter *profileAdapter)
{
PrefServiceFactory factory;
factory.set_user_prefs(new InMemoryPrefStore);
+ factory.set_command_line_prefs(base::MakeRefCounted<CommandLinePrefStoreQt>(
+ WebEngineContext::commandLine()));
PrefRegistrySimple *registry = new PrefRegistrySimple();
-
+ PrefProxyConfigTrackerImpl::RegisterPrefs(registry);
#if QT_CONFIG(webengine_spellchecker)
// Initial spellcheck settings
registry->RegisterStringPref(prefs::kAcceptLanguages, std::string());
diff --git a/src/core/qtwebengine.gni b/src/core/qtwebengine.gni
index 3ae2b999c..0bb8f0cdb 100644
--- a/src/core/qtwebengine.gni
+++ b/src/core/qtwebengine.gni
@@ -26,6 +26,7 @@ deps = [
"//components/web_cache/browser",
"//components/web_cache/renderer",
"//components/spellcheck:buildflags",
+ "//components/proxy_config",
"//content/public/app:browser",
"//content",
"//media:media_buildflags",
diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp
index a357196b0..90b1bffa5 100644
--- a/src/core/web_engine_context.cpp
+++ b/src/core/web_engine_context.cpp
@@ -360,6 +360,7 @@ WebEngineContext::WebEngineContext()
base::TaskScheduler::Create("Browser");
m_contentRunner.reset(content::ContentMainRunner::Create());
m_browserRunner.reset(content::BrowserMainRunner::Create());
+
#ifdef Q_OS_LINUX
// Call qputenv before BrowserMainRunnerImpl::Initialize is called.
// http://crbug.com/245466
@@ -375,33 +376,18 @@ WebEngineContext::WebEngineContext()
// Allow us to inject javascript like any webview toolkit.
content::RenderFrameHost::AllowInjectingJavaScriptForAndroidWebView();
- base::CommandLine::CreateEmpty();
- base::CommandLine* parsedCommandLine = base::CommandLine::ForCurrentProcess();
QStringList appArgs = QCoreApplication::arguments();
- if (qEnvironmentVariableIsSet(kChromiumFlagsEnv)) {
- appArgs = appArgs.mid(0, 1); // Take application name and drop the rest
- appArgs.append(QString::fromLocal8Bit(qgetenv(kChromiumFlagsEnv)).split(' '));
- }
- bool enableWebGLSoftwareRendering =
- appArgs.removeAll(QStringLiteral("--enable-webgl-software-rendering"));
+ bool enableWebGLSoftwareRendering = appArgs.contains(QStringLiteral("--enable-webgl-software-rendering"));
bool useEmbeddedSwitches = false;
#if defined(QTWEBENGINE_EMBEDDED_SWITCHES)
- useEmbeddedSwitches = !appArgs.removeAll(QStringLiteral("--disable-embedded-switches"));
-#else
- useEmbeddedSwitches = appArgs.removeAll(QStringLiteral("--enable-embedded-switches"));
-#endif
- base::CommandLine::StringVector argv;
- argv.resize(appArgs.size());
-#if defined(Q_OS_WIN)
- for (int i = 0; i < appArgs.size(); ++i)
- argv[i] = toString16(appArgs[i]);
+ useEmbeddedSwitches = !appArgs.contains(QStringLiteral("--disable-embedded-switches"));
#else
- for (int i = 0; i < appArgs.size(); ++i)
- argv[i] = appArgs[i].toStdString();
+ useEmbeddedSwitches = appArgs.contains(QStringLiteral("--enable-embedded-switches"));
#endif
- parsedCommandLine->InitFromArgv(argv);
+
+ base::CommandLine* parsedCommandLine = commandLine();
parsedCommandLine->AppendSwitchPath(switches::kBrowserSubprocessPath, WebEngineLibraryInfo::getPath(content::CHILD_PROCESS_EXE));
@@ -660,4 +646,34 @@ gpu::SyncPointManager *WebEngineContext::syncPointManager()
return s_syncPointManager.load();
}
+base::CommandLine* WebEngineContext::commandLine() {
+ if (base::CommandLine::CreateEmpty()) {
+ base::CommandLine* parsedCommandLine = base::CommandLine::ForCurrentProcess();
+ QStringList appArgs = QCoreApplication::arguments();
+ if (qEnvironmentVariableIsSet(kChromiumFlagsEnv)) {
+ appArgs = appArgs.mid(0, 1); // Take application name and drop the rest
+ appArgs.append(QString::fromLocal8Bit(qgetenv(kChromiumFlagsEnv)).split(' '));
+ }
+#ifdef Q_OS_WIN
+ appArgs.removeAll(QStringLiteral("--enable-webgl-software-rendering"));
+#endif
+ appArgs.removeAll(QStringLiteral("--disable-embedded-switches"));
+ appArgs.removeAll(QStringLiteral("--enable-embedded-switches"));
+
+ base::CommandLine::StringVector argv;
+ argv.resize(appArgs.size());
+#if defined(Q_OS_WIN)
+ for (int i = 0; i < appArgs.size(); ++i)
+ argv[i] = toString16(appArgs[i]);
+#else
+ for (int i = 0; i < appArgs.size(); ++i)
+ argv[i] = appArgs[i].toStdString();
+#endif
+ parsedCommandLine->InitFromArgv(argv);
+ return parsedCommandLine;
+ } else {
+ return base::CommandLine::ForCurrentProcess();
+ }
+}
+
} // namespace
diff --git a/src/core/web_engine_context.h b/src/core/web_engine_context.h
index ad02ddf4d..4dc5251cc 100644
--- a/src/core/web_engine_context.h
+++ b/src/core/web_engine_context.h
@@ -47,6 +47,7 @@
namespace base {
class RunLoop;
+class CommandLine;
}
namespace content {
@@ -95,6 +96,7 @@ public:
void addProfileAdapter(ProfileAdapter *profileAdapter);
void removeProfileAdapter(ProfileAdapter *profileAdapter);
void destroy();
+ static base::CommandLine* commandLine();
static gpu::SyncPointManager *syncPointManager();