fix: only call NetworkService::SetUpHttpAuth once.

This commit is contained in:
Charles Kerr 2018-10-05 15:34:45 -05:00 коммит произвёл Jeremy Apthorp
Родитель f668fc8d02
Коммит f027e62b2a
2 изменённых файлов: 39 добавлений и 32 удалений

Просмотреть файл

@ -3,13 +3,16 @@
// found in the LICENSE file.
#include "atom/browser/io_thread.h"
#include "atom/common/options_switches.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/network_service.h"
#if defined(USE_NSS_CERTS)
#include "net/cert_net/nss_ocsp.h"
@ -24,6 +27,33 @@ using content::BrowserThread;
namespace atom {
namespace {
network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
network::mojom::HttpAuthStaticParamsPtr auth_static_params =
network::mojom::HttpAuthStaticParams::New();
auth_static_params->supported_schemes = {"basic", "digest", "ntlm",
"negotiate"};
return auth_static_params;
}
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams(
const base::CommandLine& command_line) {
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
network::mojom::HttpAuthDynamicParams::New();
auth_dynamic_params->server_whitelist =
command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist);
auth_dynamic_params->delegate_whitelist = command_line.GetSwitchValueASCII(
switches::kAuthNegotiateDelegateWhitelist);
return auth_dynamic_params;
}
} // namespace
IOThread::IOThread(net_log::ChromeNetLog* net_log) : net_log_(net_log) {
BrowserThread::SetIOThreadDelegate(this);
}
@ -33,6 +63,14 @@ IOThread::~IOThread() {
}
void IOThread::Init() {
// Create the network service, so that shared host resolver
// gets created which is required to set the auth preferences below.
auto& command_line = *base::CommandLine::ForCurrentProcess();
auto* network_service = content::GetNetworkServiceImpl();
network_service->SetUpHttpAuth(CreateHttpAuthStaticParams());
network_service->ConfigureHttpAuthPrefs(
CreateHttpAuthDynamicParams(command_line));
net::URLRequestContextBuilder builder;
// TODO(deepak1556): We need to respoect user proxy configurations,
// the following initialization has to happen before any request

Просмотреть файл

@ -17,7 +17,6 @@
#include "atom/browser/net/atom_network_delegate.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "atom/browser/net/http_protocol_handler.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/strings/string_util.h"
#include "base/task_scheduler/post_task.h"
@ -106,29 +105,6 @@ network::mojom::NetworkContextParamsPtr CreateDefaultNetworkContextParams(
return network_context_params;
}
network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
network::mojom::HttpAuthStaticParamsPtr auth_static_params =
network::mojom::HttpAuthStaticParams::New();
auth_static_params->supported_schemes = {"basic", "digest", "ntlm",
"negotiate"};
return auth_static_params;
}
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams(
const base::CommandLine& command_line) {
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
network::mojom::HttpAuthDynamicParams::New();
auth_dynamic_params->server_whitelist =
command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist);
auth_dynamic_params->delegate_whitelist = command_line.GetSwitchValueASCII(
switches::kAuthNegotiateDelegateWhitelist);
return auth_dynamic_params;
}
void SetupAtomURLRequestJobFactory(
content::ProtocolHandlerMap* protocol_handlers,
net::URLRequestContext* url_request_context,
@ -335,14 +311,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
return nullptr;
if (!url_request_context_) {
auto& command_line = *base::CommandLine::ForCurrentProcess();
// Create the network service, so that shared host resolver
// gets created which is required to set the auth preferences below.
auto* network_service = content::GetNetworkServiceImpl();
network_service->SetUpHttpAuth(CreateHttpAuthStaticParams());
network_service->ConfigureHttpAuthPrefs(
CreateHttpAuthDynamicParams(command_line));
std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
std::make_unique<network::URLRequestContextBuilderMojo>();
builder->set_network_delegate(std::make_unique<AtomNetworkDelegate>());
@ -356,6 +324,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
builder->set_ct_verifier(std::make_unique<net::MultiLogCTVerifier>());
auto* network_service = content::GetNetworkServiceImpl();
network_context_ = network_service->CreateNetworkContextWithBuilder(
std::move(context_handle_->main_network_context_request_),
std::move(context_handle_->main_network_context_params_),