refactor: nws13n: session.allowNTLMCredentialsForDomains (#18129)
This commit is contained in:
parent
f4c792d014
commit
2dbd2c07e4
3 changed files with 17 additions and 21 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/media/media_device_id_salt.h"
|
#include "atom/browser/media/media_device_id_salt.h"
|
||||||
#include "atom/browser/net/atom_cert_verifier.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/browser/session_preferences.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/content_converter.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/net_converter.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/guid.h"
|
#include "base/guid.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
|
@ -46,6 +48,7 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/download_item_utils.h"
|
#include "content/public/browser/download_item_utils.h"
|
||||||
#include "content/public/browser/download_manager_delegate.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 "content/public/browser/storage_partition.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
@ -177,19 +180,6 @@ void SetCertVerifyProcInIO(
|
||||||
->SetVerifyProc(proc);
|
->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,
|
void DownloadIdCallback(content::DownloadManager* download_manager,
|
||||||
const base::FilePath& path,
|
const base::FilePath& path,
|
||||||
const std::vector<GURL>& url_chain,
|
const std::vector<GURL>& url_chain,
|
||||||
|
@ -522,11 +512,9 @@ v8::Local<v8::Promise> Session::ClearAuthCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
|
void Session::AllowNTLMCredentialsForDomains(const std::string& domains) {
|
||||||
base::PostTaskWithTraits(
|
auto auth_params = CreateHttpAuthDynamicParams();
|
||||||
FROM_HERE, {BrowserThread::IO},
|
auth_params->server_whitelist = domains;
|
||||||
base::BindOnce(&AllowNTLMCredentialsForDomainsInIO,
|
content::GetNetworkService()->ConfigureHttpAuthPrefs(std::move(auth_params));
|
||||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
|
||||||
domains));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::SetUserAgent(const std::string& user_agent,
|
void Session::SetUserAgent(const std::string& user_agent,
|
||||||
|
|
|
@ -42,6 +42,10 @@ network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
|
||||||
return auth_static_params;
|
return auth_static_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams() {
|
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams() {
|
||||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
|
network::mojom::HttpAuthDynamicParamsPtr auth_dynamic_params =
|
||||||
|
@ -57,7 +61,7 @@ network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams() {
|
||||||
return auth_dynamic_params;
|
return auth_dynamic_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace atom
|
||||||
|
|
||||||
// SharedURLLoaderFactory backed by a SystemNetworkContextManager and its
|
// SharedURLLoaderFactory backed by a SystemNetworkContextManager and its
|
||||||
// network context. Transparently handles crashes.
|
// network context. Transparently handles crashes.
|
||||||
|
@ -191,7 +195,7 @@ void SystemNetworkContextManager::SetUp(
|
||||||
*network_context_params = CreateDefaultNetworkContextParams();
|
*network_context_params = CreateDefaultNetworkContextParams();
|
||||||
}
|
}
|
||||||
*http_auth_static_params = CreateHttpAuthStaticParams();
|
*http_auth_static_params = CreateHttpAuthStaticParams();
|
||||||
*http_auth_dynamic_params = CreateHttpAuthDynamicParams();
|
*http_auth_dynamic_params = atom::CreateHttpAuthDynamicParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -230,7 +234,7 @@ void SystemNetworkContextManager::OnNetworkServiceCreated(
|
||||||
return;
|
return;
|
||||||
|
|
||||||
network_service->SetUpHttpAuth(CreateHttpAuthStaticParams());
|
network_service->SetUpHttpAuth(CreateHttpAuthStaticParams());
|
||||||
network_service->ConfigureHttpAuthPrefs(CreateHttpAuthDynamicParams());
|
network_service->ConfigureHttpAuthPrefs(atom::CreateHttpAuthDynamicParams());
|
||||||
|
|
||||||
// The system NetworkContext must be created first, since it sets
|
// The system NetworkContext must be created first, since it sets
|
||||||
// |primary_network_context| to true.
|
// |primary_network_context| to true.
|
||||||
|
|
|
@ -27,6 +27,10 @@ namespace net_log {
|
||||||
class NetExportFileWriter;
|
class NetExportFileWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
network::mojom::HttpAuthDynamicParamsPtr CreateHttpAuthDynamicParams();
|
||||||
|
}
|
||||||
|
|
||||||
// Responsible for creating and managing access to the system NetworkContext.
|
// Responsible for creating and managing access to the system NetworkContext.
|
||||||
// Lives on the UI thread. The NetworkContext this owns is intended for requests
|
// 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
|
// not associated with a session. It stores no data on disk, and has no HTTP
|
||||||
|
|
Loading…
Add table
Reference in a new issue