OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_URL_REQUEST_PROTOCOL_INTERCEPT_JOB_FACTORY_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |
6 #define NET_URL_REQUEST_PROTOCOL_INTERCEPT_JOB_FACTORY_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
14 #include "net/url_request/url_request_job_factory.h" | 14 #include "net/url_request/url_request_job_factory.h" |
15 | 15 |
16 class GURL; | 16 class GURL; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 class URLRequest; | 20 class URLRequest; |
21 class URLRequestJob; | 21 class URLRequestJob; |
| 22 class URLRequestInterceptor; |
22 | 23 |
23 // This class acts as a wrapper for URLRequestJobFactory. |protocol_handler_| is | 24 // This class acts as a wrapper for URLRequestJobFactory. The |
24 // given the option of creating a URLRequestJob for each potential URLRequest. | 25 // URLRequestInteceptor is given the option of creating a URLRequestJob for each |
25 // If |protocol_handler_| does not create a job (i.e. MaybeCreateJob() returns | 26 // URLRequest. If the interceptor does not create a job, the URLRequest is |
26 // NULL) the URLRequest is forwarded to the |job_factory_| to be handled there. | 27 // forwarded to the wrapped URLRequestJobFactory instead. |
27 // Only the MaybeCreateJob() member of |protocol_handler_| is called; the | 28 // |
28 // IsSafeRedirectTarget() member is not used. | 29 // This class is only intended for use in intercepting requests before they |
29 class NET_EXPORT ProtocolInterceptJobFactory : public URLRequestJobFactory { | 30 // are passed on to their default ProtocolHandler. Each supported scheme should |
| 31 // have its own ProtocolHandler. |
| 32 class NET_EXPORT URLRequestInterceptingJobFactory |
| 33 : public URLRequestJobFactory { |
30 public: | 34 public: |
31 ProtocolInterceptJobFactory(scoped_ptr<URLRequestJobFactory> job_factory, | 35 URLRequestInterceptingJobFactory( |
32 scoped_ptr<ProtocolHandler> protocol_handler); | 36 scoped_ptr<URLRequestJobFactory> job_factory, |
33 virtual ~ProtocolInterceptJobFactory(); | 37 scoped_ptr<URLRequestInterceptor> interceptor); |
| 38 virtual ~URLRequestInterceptingJobFactory(); |
34 | 39 |
35 // URLRequestJobFactory implementation | 40 // URLRequestJobFactory implementation |
36 virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( | 41 virtual URLRequestJob* MaybeCreateJobWithProtocolHandler( |
37 const std::string& scheme, | 42 const std::string& scheme, |
38 URLRequest* request, | 43 URLRequest* request, |
39 NetworkDelegate* network_delegate) const OVERRIDE; | 44 NetworkDelegate* network_delegate) const OVERRIDE; |
40 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; | 45 virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE; |
41 virtual bool IsHandledURL(const GURL& url) const OVERRIDE; | 46 virtual bool IsHandledURL(const GURL& url) const OVERRIDE; |
42 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE; | 47 virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE; |
43 | 48 |
44 private: | 49 private: |
45 scoped_ptr<URLRequestJobFactory> job_factory_; | 50 scoped_ptr<URLRequestJobFactory> job_factory_; |
46 scoped_ptr<ProtocolHandler> protocol_handler_; | 51 scoped_ptr<URLRequestInterceptor> interceptor_; |
47 | 52 |
48 DISALLOW_COPY_AND_ASSIGN(ProtocolInterceptJobFactory); | 53 DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptingJobFactory); |
49 }; | 54 }; |
50 | 55 |
51 } // namespace net | 56 } // namespace net |
52 | 57 |
53 #endif // NET_URL_REQUEST_PROTOCOL_INTERCEPT_JOB_FACTORY_H_ | 58 #endif // NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |
OLD | NEW |