Enables compositing support for webview.
[chromium-blink-merge.git] / net / url_request / url_request_job_factory_impl.cc
blobaaeed79132b443ead616f4b3e0d360f6de03c328
1 // Copyright (c) 2011 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.
5 #include "net/url_request/url_request_job_factory_impl.h"
7 #include "base/stl_util.h"
8 #include "googleurl/src/gurl.h"
9 #include "net/base/load_flags.h"
10 #include "net/url_request/url_request_job_manager.h"
12 namespace net {
14 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {}
16 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {
17 STLDeleteValues(&protocol_handler_map_);
18 STLDeleteElements(&interceptors_);
21 bool URLRequestJobFactoryImpl::SetProtocolHandler(
22 const std::string& scheme,
23 ProtocolHandler* protocol_handler) {
24 DCHECK(CalledOnValidThread());
26 if (!protocol_handler) {
27 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
28 if (it == protocol_handler_map_.end())
29 return false;
31 delete it->second;
32 protocol_handler_map_.erase(it);
33 return true;
36 if (ContainsKey(protocol_handler_map_, scheme))
37 return false;
38 protocol_handler_map_[scheme] = protocol_handler;
39 return true;
42 void URLRequestJobFactoryImpl::AddInterceptor(Interceptor* interceptor) {
43 DCHECK(CalledOnValidThread());
44 CHECK(interceptor);
46 interceptors_.push_back(interceptor);
49 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithInterceptor(
50 URLRequest* request, NetworkDelegate* network_delegate) const {
51 DCHECK(CalledOnValidThread());
52 URLRequestJob* job = NULL;
54 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
55 InterceptorList::const_iterator i;
56 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
57 job = (*i)->MaybeIntercept(request, network_delegate);
58 if (job)
59 return job;
62 return NULL;
65 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler(
66 const std::string& scheme,
67 URLRequest* request,
68 NetworkDelegate* network_delegate) const {
69 DCHECK(CalledOnValidThread());
70 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
71 if (it == protocol_handler_map_.end())
72 return NULL;
73 return it->second->MaybeCreateJob(request, network_delegate);
76 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptRedirect(
77 const GURL& location,
78 URLRequest* request,
79 NetworkDelegate* network_delegate) const {
80 DCHECK(CalledOnValidThread());
81 URLRequestJob* job = NULL;
83 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
84 InterceptorList::const_iterator i;
85 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
86 job = (*i)->MaybeInterceptRedirect(location, request, network_delegate);
87 if (job)
88 return job;
91 return NULL;
94 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse(
95 URLRequest* request, NetworkDelegate* network_delegate) const {
96 DCHECK(CalledOnValidThread());
97 URLRequestJob* job = NULL;
99 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) {
100 InterceptorList::const_iterator i;
101 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
102 job = (*i)->MaybeInterceptResponse(request, network_delegate);
103 if (job)
104 return job;
107 return NULL;
110 bool URLRequestJobFactoryImpl::IsHandledProtocol(
111 const std::string& scheme) const {
112 DCHECK(CalledOnValidThread());
113 InterceptorList::const_iterator i;
114 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
115 if ((*i)->WillHandleProtocol(scheme))
116 return true;
118 return ContainsKey(protocol_handler_map_, scheme) ||
119 URLRequestJobManager::GetInstance()->SupportsScheme(scheme);
122 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const {
123 if (!url.is_valid()) {
124 // We handle error cases.
125 return true;
127 return IsHandledProtocol(url.scheme());
130 } // namespace net