Move the NTLM check to the URLRequestContextGetter delegate

This commit is contained in:
Paul Betts 2015-10-19 12:51:01 -07:00
parent 91a62640ab
commit 0d63eaa07b
2 changed files with 46 additions and 33 deletions

View file

@ -84,22 +84,24 @@ const char kProxyPacUrl[] = "proxy-pac-url";
} // namespace
ExplicitURLSecurityManager::ExplicitURLSecurityManager() :
allow_default_creds_(false),
URLRequestContextGetter::DelegateURLSecurityManager::DelegateURLSecurityManager
(URLRequestContextGetter::Delegate* delegate) :
delegate_(delegate) {}
bool URLRequestContextGetter::DelegateURLSecurityManager::CanUseDefaultCredentials
(const GURL& auth_origin) const {
return delegate_->AllowNTLMCredentialsForDomain(auth_origin);
}
bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate
(const GURL& auth_origin) const {
return delegate_->CanDelegateURLSecurity(auth_origin);
}
URLRequestContextGetter::Delegate::Delegate() :
orig_url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)) {}
bool ExplicitURLSecurityManager::CanUseDefaultCredentials(const GURL& auth_origin) const {
if (allow_default_creds_) {
return true;
}
return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin);
}
bool ExplicitURLSecurityManager::CanDelegate(const GURL& auth_origin) const {
return orig_url_sec_mgr_->CanDelegate(auth_origin);
}
std::string URLRequestContextGetter::Delegate::GetUserAgent() {
return base::EmptyString();
}
@ -144,6 +146,15 @@ net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService
return new net::SSLConfigServiceDefaults;
}
bool URLRequestContextGetter::Delegate::AllowNTLMCredentialsForDomain(const GURL& auth_origin) {
return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin);
}
bool URLRequestContextGetter::Delegate::CanDelegateURLSecurity(const GURL& auth_origin) {
return orig_url_sec_mgr_->CanDelegate(auth_origin);
}
URLRequestContextGetter::URLRequestContextGetter(
Delegate* delegate,
DevToolsNetworkController* controller,
@ -161,7 +172,7 @@ URLRequestContextGetter::URLRequestContextGetter(
in_memory_(in_memory),
io_loop_(io_loop),
file_loop_(file_loop),
url_sec_mgr_(new ExplicitURLSecurityManager()),
url_sec_mgr_(new URLRequestContextGetter::DelegateURLSecurityManager(delegate)),
protocol_interceptors_(protocol_interceptors.Pass()) {
// Must first be created on the UI thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

View file

@ -30,27 +30,11 @@ namespace brightray {
class DevToolsNetworkController;
class NetLog;
class ExplicitURLSecurityManager : public net::URLSecurityManager {
public:
ExplicitURLSecurityManager();
bool CanUseDefaultCredentials(const GURL& auth_origin) const override;
bool CanDelegate(const GURL& auth_origin) const override;
void AllowNTLMCredentialsForAllDomains(bool should_allow) { allow_default_creds_ = should_allow; }
private:
bool allow_default_creds_;
scoped_ptr<net::URLSecurityManager> orig_url_sec_mgr_;
DISALLOW_COPY_AND_ASSIGN(ExplicitURLSecurityManager);
};
class URLRequestContextGetter : public net::URLRequestContextGetter {
public:
class Delegate {
public:
Delegate() {}
Delegate();
virtual ~Delegate() {}
virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; }
@ -61,6 +45,24 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory(
const base::FilePath& base_path);
virtual net::SSLConfigService* CreateSSLConfigService();
virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin);
virtual bool CanDelegateURLSecurity(const GURL& auth_origin);
private:
scoped_ptr<net::URLSecurityManager> orig_url_sec_mgr_;
};
class DelegateURLSecurityManager : public net::URLSecurityManager {
public:
DelegateURLSecurityManager(URLRequestContextGetter::Delegate* delegate);
bool CanUseDefaultCredentials(const GURL& auth_origin) const override;
bool CanDelegate(const GURL& auth_origin) const override;
private:
URLRequestContextGetter::Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(DelegateURLSecurityManager);
};
URLRequestContextGetter(
@ -98,7 +100,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
scoped_ptr<net::URLRequestContextStorage> storage_;
scoped_ptr<net::URLRequestContext> url_request_context_;
scoped_ptr<net::HostMappingRules> host_mapping_rules_;
scoped_ptr<ExplicitURLSecurityManager> url_sec_mgr_;
scoped_ptr<net::URLSecurityManager> url_sec_mgr_;
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector protocol_interceptors_;