refactor: nws13n: session.allowNTLMCredentialsForDomains (#18129)

This commit is contained in:
Jeremy Apthorp 2019-05-29 16:43:06 -07:00 committed by GitHub
parent f4c792d014
commit 2dbd2c07e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 21 deletions

View file

@ -22,6 +22,7 @@
#include "atom/browser/browser.h"
#include "atom/browser/media/media_device_id_salt.h"
#include "atom/browser/net/atom_cert_verifier.h"
#include "atom/browser/net/system_network_context_manager.h"
#include "atom/browser/session_preferences.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/content_converter.h"
@ -30,6 +31,7 @@
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "base/files/file_path.h"
#include "base/guid.h"
#include "base/strings/string_number_conversions.h"
@ -46,6 +48,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager_delegate.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/storage_partition.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
@ -177,19 +180,6 @@ void SetCertVerifyProcInIO(
->SetVerifyProc(proc);
}
void AllowNTLMCredentialsForDomainsInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const std::string& domains) {
auto* request_context = context_getter->GetURLRequestContext();
auto* auth_handler = request_context->http_auth_handler_factory();
if (auth_handler) {
auto* auth_preferences = const_cast<net::HttpAuthPreferences*>(
auth_handler->http_auth_preferences());
if (auth_preferences)
auth_preferences->SetServerWhitelist(domains);
}
}
void DownloadIdCallback(content::DownloadManager* download_manager,
const base::FilePath& path,
const std::vector<GURL>& url_chain,
@ -522,11 +512,9 @@ v8::Local<v8::Promise> Session::ClearAuthCache() {
}
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&AllowNTLMCredentialsForDomainsInIO,
WrapRefCounted(browser_context_->GetRequestContext()),
domains));
auto auth_params = CreateHttpAuthDynamicParams();
auth_params->server_whitelist = domains;
content::GetNetworkService()->ConfigureHttpAuthPrefs(std::move(auth_params));
}
void Session::SetUserAgent(const std::string& user_agent,

View file

@ -42,6 +42,10 @@ network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
return auth_static_params;
}
} // namespace
namespace atom {
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams() {
auto* command_line = base::CommandLine::ForCurrentProcess();
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
@ -57,7 +61,7 @@ network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams() {
return auth_dynamic_params;
}
} // namespace
} // namespace atom
// SharedURLLoaderFactory backed by a SystemNetworkContextManager and its
// network context. Transparently handles crashes.
@ -191,7 +195,7 @@ void SystemNetworkContextManager::SetUp(
*network_context_params = CreateDefaultNetworkContextParams();
}
*http_auth_static_params = CreateHttpAuthStaticParams();
*http_auth_dynamic_params = CreateHttpAuthDynamicParams();
*http_auth_dynamic_params = atom::CreateHttpAuthDynamicParams();
}
// static
@ -230,7 +234,7 @@ void SystemNetworkContextManager::OnNetworkServiceCreated(
return;
network_service->SetUpHttpAuth(CreateHttpAuthStaticParams());
network_service->ConfigureHttpAuthPrefs(CreateHttpAuthDynamicParams());
network_service->ConfigureHttpAuthPrefs(atom::CreateHttpAuthDynamicParams());
// The system NetworkContext must be created first, since it sets
// |primary_network_context| to true.

View file

@ -27,6 +27,10 @@ namespace net_log {
class NetExportFileWriter;
}
namespace atom {
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams();
}
// Responsible for creating and managing access to the system NetworkContext.
// Lives on the UI thread. The NetworkContext this owns is intended for requests
// not associated with a session. It stores no data on disk, and has no HTTP