mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 1 | // Copyright 2014 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. |
| 4 | |
| 5 | #ifndef NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |
| 6 | #define NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |
| 7 | |
danakj | 8522a25b | 2016-04-16 00:17:36 | [diff] [blame] | 8 | #include <memory> |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 9 | #include <string> |
| 10 | |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 12 | #include "base/macros.h" |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 13 | #include "net/base/net_export.h" |
| 14 | #include "net/url_request/url_request_job_factory.h" |
| 15 | |
| 16 | class GURL; |
| 17 | |
| 18 | namespace net { |
| 19 | |
| 20 | class URLRequest; |
| 21 | class URLRequestJob; |
| 22 | class URLRequestInterceptor; |
| 23 | |
| 24 | // This class acts as a wrapper for URLRequestJobFactory. The |
| 25 | // URLRequestInteceptor is given the option of creating a URLRequestJob for each |
| 26 | // URLRequest. If the interceptor does not create a job, the URLRequest is |
| 27 | // forwarded to the wrapped URLRequestJobFactory instead. |
| 28 | // |
| 29 | // This class is only intended for use in intercepting requests before they |
| 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 { |
| 34 | public: |
pauljensen | fd031f1 | 2016-11-21 13:52:57 | [diff] [blame] | 35 | // Takes ownership of |job_factory| and |interceptor|. |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 36 | URLRequestInterceptingJobFactory( |
danakj | 8522a25b | 2016-04-16 00:17:36 | [diff] [blame] | 37 | std::unique_ptr<URLRequestJobFactory> job_factory, |
| 38 | std::unique_ptr<URLRequestInterceptor> interceptor); |
pauljensen | fd031f1 | 2016-11-21 13:52:57 | [diff] [blame] | 39 | // Does not take ownership of |job_factory| and |interceptor|. Necessary if |
| 40 | // ownership is held elsewhere. |
| 41 | URLRequestInterceptingJobFactory(URLRequestJobFactory* job_factory, |
| 42 | URLRequestInterceptor* interceptor); |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 43 | ~URLRequestInterceptingJobFactory() override; |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 44 | |
| 45 | // URLRequestJobFactory implementation |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 46 | URLRequestJob* MaybeCreateJobWithProtocolHandler( |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 47 | const std::string& scheme, |
| 48 | URLRequest* request, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 49 | NetworkDelegate* network_delegate) const override; |
bengr | 1bf8e94 | 2014-11-07 01:36:50 | [diff] [blame] | 50 | |
| 51 | URLRequestJob* MaybeInterceptRedirect( |
| 52 | URLRequest* request, |
| 53 | NetworkDelegate* network_delegate, |
| 54 | const GURL& location) const override; |
| 55 | |
| 56 | URLRequestJob* MaybeInterceptResponse( |
| 57 | URLRequest* request, |
| 58 | NetworkDelegate* network_delegate) const override; |
| 59 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 60 | bool IsHandledProtocol(const std::string& scheme) const override; |
| 61 | bool IsHandledURL(const GURL& url) const override; |
| 62 | bool IsSafeRedirectTarget(const GURL& location) const override; |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 63 | |
| 64 | private: |
pauljensen | fd031f1 | 2016-11-21 13:52:57 | [diff] [blame] | 65 | // |owning_| indicates if this object owns |job_factory_| and |interceptor_|. |
| 66 | bool owning_; |
| 67 | URLRequestJobFactory* job_factory_; |
| 68 | URLRequestInterceptor* interceptor_; |
mmenke@chromium.org | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptingJobFactory); |
| 71 | }; |
| 72 | |
| 73 | } // namespace net |
| 74 | |
| 75 | #endif // NET_URL_REQUEST_URL_REQUEST_INTERCEPTING_JOB_FACTORY_H_ |