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"
15 class AppCacheRequestHandler
;
16 class AppCacheServiceImpl
;
18 // An interceptor to hijack requests and potentially service them out of
20 class CONTENT_EXPORT AppCacheInterceptor
21 : public net::URLRequest::Interceptor
{
23 // Registers a singleton instance with the net library.
24 // Should be called early in the IO thread prior to initiating requests.
25 static void EnsureRegistered() {
29 // Must be called to make a request eligible for retrieval from an appcache.
30 static void SetExtraRequestInfo(net::URLRequest
* request
,
31 AppCacheServiceImpl
* service
,
34 ResourceType resource_type
);
36 // May be called after response headers are complete to retrieve extra
37 // info about the response.
38 static void GetExtraResponseInfo(net::URLRequest
* request
,
42 // Methods to support cross site navigations.
43 static void PrepareForCrossSiteTransfer(net::URLRequest
* request
,
45 static void CompleteCrossSiteTransfer(net::URLRequest
* request
,
49 static AppCacheInterceptor
* GetInstance();
52 // Override from net::URLRequest::Interceptor:
53 virtual net::URLRequestJob
* MaybeIntercept(
54 net::URLRequest
* request
,
55 net::NetworkDelegate
* network_delegate
) OVERRIDE
;
56 virtual net::URLRequestJob
* MaybeInterceptResponse(
57 net::URLRequest
* request
,
58 net::NetworkDelegate
* network_delegate
) OVERRIDE
;
59 virtual net::URLRequestJob
* MaybeInterceptRedirect(
60 net::URLRequest
* request
,
61 net::NetworkDelegate
* network_delegate
,
62 const GURL
& location
) OVERRIDE
;
65 friend struct DefaultSingletonTraits
<AppCacheInterceptor
>;
67 AppCacheInterceptor();
68 virtual ~AppCacheInterceptor();
70 static void SetHandler(net::URLRequest
* request
,
71 AppCacheRequestHandler
* handler
);
72 static AppCacheRequestHandler
* GetHandler(net::URLRequest
* request
);
74 DISALLOW_COPY_AND_ASSIGN(AppCacheInterceptor
);
77 } // namespace content
79 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_INTERCEPTOR_H_