This source file includes following definitions.
- SetProtocolHandler
- MaybeCreateJobWithProtocolHandler
- IsHandledProtocol
- IsHandledURL
- IsSafeRedirectTarget
#include "net/url_request/url_request_job_factory_impl.h"
#include "base/stl_util.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request_job_manager.h"
#include "url/gurl.h"
namespace net {
URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {
STLDeleteValues(&protocol_handler_map_);
}
bool URLRequestJobFactoryImpl::SetProtocolHandler(
const std::string& scheme,
ProtocolHandler* protocol_handler) {
DCHECK(CalledOnValidThread());
if (!protocol_handler) {
ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
if (it == protocol_handler_map_.end())
return false;
delete it->second;
protocol_handler_map_.erase(it);
return true;
}
if (ContainsKey(protocol_handler_map_, scheme))
return false;
protocol_handler_map_[scheme] = protocol_handler;
return true;
}
URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
const std::string& scheme,
URLRequest* request,
NetworkDelegate* network_delegate) const {
DCHECK(CalledOnValidThread());
ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
if (it == protocol_handler_map_.end())
return NULL;
return it->second->MaybeCreateJob(request, network_delegate);
}
bool URLRequestJobFactoryImpl::IsHandledProtocol(
const std::string& scheme) const {
DCHECK(CalledOnValidThread());
return ContainsKey(protocol_handler_map_, scheme) ||
URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
}
bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const {
if (!url.is_valid()) {
return true;
}
return IsHandledProtocol(url.scheme());
}
bool URLRequestJobFactoryImpl::IsSafeRedirectTarget(
const GURL& location) const {
DCHECK(CalledOnValidThread());
if (!location.is_valid()) {
return true;
}
ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(
location.scheme());
if (it == protocol_handler_map_.end()) {
return true;
}
return it->second->IsSafeRedirectTarget(location);
}
}