| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_auth_handler_factory.h" | 5 #include "net/http/http_auth_handler_factory.h" |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_auth_filter.h" | 10 #include "net/http/http_auth_filter.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 "basic", new HttpAuthHandlerBasic::Factory()); | 46 "basic", new HttpAuthHandlerBasic::Factory()); |
| 47 registry_factory->RegisterSchemeFactory( | 47 registry_factory->RegisterSchemeFactory( |
| 48 "digest", new HttpAuthHandlerDigest::Factory()); | 48 "digest", new HttpAuthHandlerDigest::Factory()); |
| 49 registry_factory->RegisterSchemeFactory( | 49 registry_factory->RegisterSchemeFactory( |
| 50 "negotiate", new HttpAuthHandlerNegotiate::Factory()); | 50 "negotiate", new HttpAuthHandlerNegotiate::Factory()); |
| 51 registry_factory->RegisterSchemeFactory( | 51 registry_factory->RegisterSchemeFactory( |
| 52 "ntlm", new HttpAuthHandlerNTLM::Factory()); | 52 "ntlm", new HttpAuthHandlerNTLM::Factory()); |
| 53 return registry_factory; | 53 return registry_factory; |
| 54 } | 54 } |
| 55 | 55 |
| 56 namespace { |
| 57 |
| 58 bool IsSupportedScheme(const std::vector<std::string>& supported_schemes, |
| 59 const std::string& scheme) { |
| 60 std::vector<std::string>::const_iterator it = std::find( |
| 61 supported_schemes.begin(), supported_schemes.end(), scheme); |
| 62 return it != supported_schemes.end(); |
| 63 } |
| 64 |
| 65 } |
| 66 |
| 67 // static |
| 68 HttpAuthHandlerRegistryFactory* HttpAuthHandlerRegistryFactory::Create( |
| 69 const std::vector<std::string>& supported_schemes, |
| 70 URLSecurityManager* security_manager, |
| 71 HostResolver* host_resolver, |
| 72 bool negotiate_disable_cname_lookup, |
| 73 bool negotiate_enable_port) { |
| 74 HttpAuthHandlerRegistryFactory* registry_factory = |
| 75 new HttpAuthHandlerRegistryFactory(); |
| 76 if (IsSupportedScheme(supported_schemes, "basic")) |
| 77 registry_factory->RegisterSchemeFactory( |
| 78 "basic", new HttpAuthHandlerBasic::Factory()); |
| 79 if (IsSupportedScheme(supported_schemes, "digest")) |
| 80 registry_factory->RegisterSchemeFactory( |
| 81 "digest", new HttpAuthHandlerDigest::Factory()); |
| 82 if (IsSupportedScheme(supported_schemes, "ntlm")) { |
| 83 HttpAuthHandlerNTLM::Factory* ntlm_factory = |
| 84 new HttpAuthHandlerNTLM::Factory(); |
| 85 ntlm_factory->set_url_security_manager(security_manager); |
| 86 registry_factory->RegisterSchemeFactory("ntlm", ntlm_factory); |
| 87 } |
| 88 if (IsSupportedScheme(supported_schemes, "negotiate")) { |
| 89 HttpAuthHandlerNegotiate::Factory* negotiate_factory = |
| 90 new HttpAuthHandlerNegotiate::Factory(); |
| 91 negotiate_factory->set_url_security_manager(security_manager); |
| 92 DCHECK(host_resolver != NULL || negotiate_disable_cname_lookup); |
| 93 negotiate_factory->set_host_resolver(host_resolver); |
| 94 negotiate_factory->set_disable_cname_lookup(negotiate_disable_cname_lookup); |
| 95 negotiate_factory->set_use_port(negotiate_enable_port); |
| 96 registry_factory->RegisterSchemeFactory("negotiate", negotiate_factory); |
| 97 } |
| 98 |
| 99 return registry_factory; |
| 100 } |
| 101 |
| 56 HttpAuthHandlerRegistryFactory::HttpAuthHandlerRegistryFactory() { | 102 HttpAuthHandlerRegistryFactory::HttpAuthHandlerRegistryFactory() { |
| 57 } | 103 } |
| 58 | 104 |
| 59 HttpAuthHandlerRegistryFactory::~HttpAuthHandlerRegistryFactory() { | 105 HttpAuthHandlerRegistryFactory::~HttpAuthHandlerRegistryFactory() { |
| 60 STLDeleteContainerPairSecondPointers(factory_map_.begin(), | 106 STLDeleteContainerPairSecondPointers(factory_map_.begin(), |
| 61 factory_map_.end()); | 107 factory_map_.end()); |
| 62 } | 108 } |
| 63 | 109 |
| 64 void HttpAuthHandlerRegistryFactory::SetURLSecurityManager( | 110 void HttpAuthHandlerRegistryFactory::SetURLSecurityManager( |
| 65 const std::string& scheme, | 111 const std::string& scheme, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const std::string& scheme) const { | 156 const std::string& scheme) const { |
| 111 std::string lower_scheme = StringToLowerASCII(scheme); | 157 std::string lower_scheme = StringToLowerASCII(scheme); |
| 112 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); | 158 FactoryMap::const_iterator it = factory_map_.find(lower_scheme); |
| 113 if (it == factory_map_.end()) { | 159 if (it == factory_map_.end()) { |
| 114 return NULL; // |scheme| is not registered. | 160 return NULL; // |scheme| is not registered. |
| 115 } | 161 } |
| 116 return it->second; | 162 return it->second; |
| 117 } | 163 } |
| 118 | 164 |
| 119 } // namespace net | 165 } // namespace net |
| OLD | NEW |