Index: net/http/http_auth_preferences.cc |
diff --git a/net/http/http_auth_preferences.cc b/net/http/http_auth_preferences.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..51d7fa5648775284f155244830cd67716b430768 |
--- /dev/null |
+++ b/net/http/http_auth_preferences.cc |
@@ -0,0 +1,118 @@ |
+// Copyright 2015 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 "base/prefs/pref_service.h" |
+#include "base/strings/string_split.h" |
+#include "net/base/net_pref_names.h" |
+#include "net/http/http_auth_filter.h" |
+#include "net/http/http_auth_preferences.h" |
+#include "net/http/url_security_manager.h" |
+ |
+namespace net { |
+ |
+HttpAuthPreferences::HttpAuthPreferences() |
+ : security_manager_(URLSecurityManager::Create()) {} |
+ |
+HttpAuthPreferences::~HttpAuthPreferences() {} |
+ |
+void HttpAuthPreferences::RegisterPrefs(PrefRegistrySimple* registry) { |
+ registry->RegisterStringPref(prefs::kAuthSchemes, |
+ "basic,digest,ntlm,negotiate"); |
dgn
2015/11/13 18:24:17
for webview, we would need to have "basic,digest,n
|
+ registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); |
+ registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
+ registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); |
+ registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, |
+ std::string()); |
+ registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); |
+#if defined(OS_ANDROID) |
+ registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, |
+ std::string()); |
+#endif |
+} |
+ |
+void HttpAuthPreferences::Init( |
+ PrefService* local_state, |
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
+ auth_schemes_ = |
+ base::SplitString(local_state->GetString(prefs::kAuthSchemes), ",", |
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
+ negotiate_disable_cname_lookup_.Init(prefs::kDisableAuthNegotiateCnameLookup, |
+ local_state); |
+ negotiate_disable_cname_lookup_.MoveToThread(task_runner); |
+ negotiate_enable_port_.Init(prefs::kEnableAuthNegotiatePort, local_state); |
+ negotiate_enable_port_.MoveToThread(task_runner); |
+ server_whitelist_.Init(prefs::kAuthServerWhitelist, local_state, |
+ base::Bind(&HttpAuthPreferences::UpdateServerWhitelist, |
+ base::Unretained(this))); |
+ UpdateServerWhitelist(); |
+ server_whitelist_.MoveToThread(task_runner); |
+ delegate_whitelist_.Init( |
+ prefs::kAuthNegotiateDelegateWhitelist, local_state, |
+ base::Bind(&HttpAuthPreferences::UpdateDelegateWhitelist, |
+ base::Unretained(this))); |
+ UpdateDelegateWhitelist(); |
+ delegate_whitelist_.MoveToThread(task_runner); |
+#if defined(OS_ANDROID) |
+ auth_android_negotiate_account_type_.Init( |
+ prefs::kAuthAndroidNegotiateAccountType, local_state); |
+ auth_android_negotiate_account_type_.MoveToThread(task_runner); |
+#endif |
+#if defined(OS_POSIX) && !defined(OS_ANDROID) |
+ gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
+#endif |
+} |
+ |
+std::vector<std::string> HttpAuthPreferences::auth_schemes() const { |
+ return auth_schemes_; |
+} |
+ |
+bool HttpAuthPreferences::negotiate_disable_cname_lookup() const { |
+ return negotiate_disable_cname_lookup_.GetValue(); |
+} |
+ |
+bool HttpAuthPreferences::negotiate_enable_port() const { |
+ return negotiate_enable_port_.GetValue(); |
+} |
+ |
+#if defined(OS_ANDROID) |
+std::string HttpAuthPreferences::auth_android_negotiate_account_type() const { |
+ return auth_android_negotiate_account_type_.GetValue(); |
+} |
+#endif |
+#if defined(OS_POSIX) && !defined(OS_ANDROID) |
+std::string HttpAuthPreferences::gssapi_library_name() const { |
+ return gssapi_library_name_; |
+} |
+#endif |
+ |
+void HttpAuthPreferences::UpdateServerWhitelist() { |
+ std::string server_whitelist = server_whitelist_.GetValue(); |
+ if (server_whitelist.empty()) { |
+ security_manager_->SetDefaultWhitelist(scoped_ptr<HttpAuthFilter>()); |
+ } else { |
+ security_manager_->SetDefaultWhitelist(scoped_ptr<HttpAuthFilter>( |
+ new net::HttpAuthFilterWhitelist(server_whitelist))); |
+ } |
+} |
+ |
+void HttpAuthPreferences::UpdateDelegateWhitelist() { |
+ std::string delegate_whitelist = delegate_whitelist_.GetValue(); |
+ if (delegate_whitelist.empty()) { |
+ security_manager_->SetDelegateWhitelist(scoped_ptr<HttpAuthFilter>()); |
+ } else { |
+ security_manager_->SetDelegateWhitelist(scoped_ptr<HttpAuthFilter>( |
+ new net::HttpAuthFilterWhitelist(delegate_whitelist))); |
+ } |
+} |
+ |
+bool HttpAuthPreferences::CanUseDefaultCredentials( |
+ const GURL& auth_origin) const { |
+ return security_manager_->CanUseDefaultCredentials(auth_origin); |
+} |
+ |
+bool HttpAuthPreferences::CanDelegate(const GURL& auth_origin) const { |
+ return security_manager_->CanDelegate(auth_origin); |
+} |
+ |
+} // namespace net |