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.
5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_
8 #include "base/memory/singleton.h"
9 #include "content/common/content_export.h"
10 #include "content/public/common/resource_type.h"
11 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_interceptor.h"
16 class AppCacheRequestHandler
;
17 class AppCacheServiceImpl
;
19 // An interceptor to hijack requests and potentially service them out of
21 class CONTENT_EXPORT AppCacheInterceptor
22 : public net::URLRequest::Interceptor
{
24 // Registers a singleton instance with the net library.
25 // Should be called early in the IO thread prior to initiating requests.
26 static void EnsureRegistered() {
30 // Must be called to make a request eligible for retrieval from an appcache.
31 static void SetExtraRequestInfo(net::URLRequest
* request
,
32 AppCacheServiceImpl
* service
,
35 ResourceType resource_type
);
37 // May be called after response headers are complete to retrieve extra
38 // info about the response.
39 static void GetExtraResponseInfo(net::URLRequest
* request
,
43 // Methods to support cross site navigations.
44 static void PrepareForCrossSiteTransfer(net::URLRequest
* request
,
46 static void CompleteCrossSiteTransfer(net::URLRequest
* request
,
50 static AppCacheInterceptor
* GetInstance();
52 // The appcache system employs two different interceptors. The singleton
53 // AppCacheInterceptor derives URLRequest::Interceptor and is used
54 // to hijack request handling upon receipt of the response or a redirect.
55 // A separate URLRequestInterceptor derivative is used to hijack handling
56 // at the very start of request processing. The separate handler allows the
57 // content lib to order its collection of net::URLRequestInterceptors.
58 static scoped_ptr
<net::URLRequestInterceptor
> CreateStartInterceptor();
61 // Override from net::URLRequest::Interceptor:
62 net::URLRequestJob
* MaybeIntercept(
63 net::URLRequest
* request
,
64 net::NetworkDelegate
* network_delegate
) override
;
65 net::URLRequestJob
* MaybeInterceptResponse(
66 net::URLRequest
* request
,
67 net::NetworkDelegate
* network_delegate
) override
;
68 net::URLRequestJob
* MaybeInterceptRedirect(
69 net::URLRequest
* request
,
70 net::NetworkDelegate
* network_delegate
,
71 const GURL
& location
) override
;
74 friend struct DefaultSingletonTraits
<AppCacheInterceptor
>;
75 class StartInterceptor
;
77 AppCacheInterceptor();
78 ~AppCacheInterceptor() override
;
80 static void SetHandler(net::URLRequest
* request
,
81 AppCacheRequestHandler
* handler
);
82 static AppCacheRequestHandler
* GetHandler(net::URLRequest
* request
);
84 DISALLOW_COPY_AND_ASSIGN(AppCacheInterceptor
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_