OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/prefs/pref_service.h" | |
6 #include "base/strings/string_split.h" | |
7 #include "net/base/net_pref_names.h" | |
8 #include "net/http/http_auth_filter.h" | |
9 #include "net/http/http_auth_preferences.h" | |
10 #include "net/http/url_security_manager.h" | |
11 | |
12 namespace net { | |
13 | |
14 HttpAuthPreferences::HttpAuthPreferences() | |
15 : security_manager_(URLSecurityManager::Create()) {} | |
16 | |
17 HttpAuthPreferences::~HttpAuthPreferences() {} | |
18 | |
19 void HttpAuthPreferences::RegisterPrefs(PrefRegistrySimple* registry) { | |
20 registry->RegisterStringPref(prefs::kAuthSchemes, | |
21 "basic,digest,ntlm,negotiate"); | |
dgn
2015/11/13 18:24:17
for webview, we would need to have "basic,digest,n
| |
22 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); | |
23 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); | |
24 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); | |
25 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, | |
26 std::string()); | |
27 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); | |
28 #if defined(OS_ANDROID) | |
29 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, | |
30 std::string()); | |
31 #endif | |
32 } | |
33 | |
34 void HttpAuthPreferences::Init( | |
35 PrefService* local_state, | |
36 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
37 auth_schemes_ = | |
38 base::SplitString(local_state->GetString(prefs::kAuthSchemes), ",", | |
39 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
40 negotiate_disable_cname_lookup_.Init(prefs::kDisableAuthNegotiateCnameLookup, | |
41 local_state); | |
42 negotiate_disable_cname_lookup_.MoveToThread(task_runner); | |
43 negotiate_enable_port_.Init(prefs::kEnableAuthNegotiatePort, local_state); | |
44 negotiate_enable_port_.MoveToThread(task_runner); | |
45 server_whitelist_.Init(prefs::kAuthServerWhitelist, local_state, | |
46 base::Bind(&HttpAuthPreferences::UpdateServerWhitelist, | |
47 base::Unretained(this))); | |
48 UpdateServerWhitelist(); | |
49 server_whitelist_.MoveToThread(task_runner); | |
50 delegate_whitelist_.Init( | |
51 prefs::kAuthNegotiateDelegateWhitelist, local_state, | |
52 base::Bind(&HttpAuthPreferences::UpdateDelegateWhitelist, | |
53 base::Unretained(this))); | |
54 UpdateDelegateWhitelist(); | |
55 delegate_whitelist_.MoveToThread(task_runner); | |
56 #if defined(OS_ANDROID) | |
57 auth_android_negotiate_account_type_.Init( | |
58 prefs::kAuthAndroidNegotiateAccountType, local_state); | |
59 auth_android_negotiate_account_type_.MoveToThread(task_runner); | |
60 #endif | |
61 #if defined(OS_POSIX) && !defined(OS_ANDROID) | |
62 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); | |
63 #endif | |
64 } | |
65 | |
66 std::vector<std::string> HttpAuthPreferences::auth_schemes() const { | |
67 return auth_schemes_; | |
68 } | |
69 | |
70 bool HttpAuthPreferences::negotiate_disable_cname_lookup() const { | |
71 return negotiate_disable_cname_lookup_.GetValue(); | |
72 } | |
73 | |
74 bool HttpAuthPreferences::negotiate_enable_port() const { | |
75 return negotiate_enable_port_.GetValue(); | |
76 } | |
77 | |
78 #if defined(OS_ANDROID) | |
79 std::string HttpAuthPreferences::auth_android_negotiate_account_type() const { | |
80 return auth_android_negotiate_account_type_.GetValue(); | |
81 } | |
82 #endif | |
83 #if defined(OS_POSIX) && !defined(OS_ANDROID) | |
84 std::string HttpAuthPreferences::gssapi_library_name() const { | |
85 return gssapi_library_name_; | |
86 } | |
87 #endif | |
88 | |
89 void HttpAuthPreferences::UpdateServerWhitelist() { | |
90 std::string server_whitelist = server_whitelist_.GetValue(); | |
91 if (server_whitelist.empty()) { | |
92 security_manager_->SetDefaultWhitelist(scoped_ptr<HttpAuthFilter>()); | |
93 } else { | |
94 security_manager_->SetDefaultWhitelist(scoped_ptr<HttpAuthFilter>( | |
95 new net::HttpAuthFilterWhitelist(server_whitelist))); | |
96 } | |
97 } | |
98 | |
99 void HttpAuthPreferences::UpdateDelegateWhitelist() { | |
100 std::string delegate_whitelist = delegate_whitelist_.GetValue(); | |
101 if (delegate_whitelist.empty()) { | |
102 security_manager_->SetDelegateWhitelist(scoped_ptr<HttpAuthFilter>()); | |
103 } else { | |
104 security_manager_->SetDelegateWhitelist(scoped_ptr<HttpAuthFilter>( | |
105 new net::HttpAuthFilterWhitelist(delegate_whitelist))); | |
106 } | |
107 } | |
108 | |
109 bool HttpAuthPreferences::CanUseDefaultCredentials( | |
110 const GURL& auth_origin) const { | |
111 return security_manager_->CanUseDefaultCredentials(auth_origin); | |
112 } | |
113 | |
114 bool HttpAuthPreferences::CanDelegate(const GURL& auth_origin) const { | |
115 return security_manager_->CanDelegate(auth_origin); | |
116 } | |
117 | |
118 } // namespace net | |
OLD | NEW |